--- loncom/homework/default_homework.lcpm 2011/06/09 15:43:56 1.159 +++ loncom/homework/default_homework.lcpm 2013/01/21 06:16:50 1.163 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run() # -# $Id: default_homework.lcpm,v 1.159 2011/06/09 15:43:56 www Exp $ +# $Id: default_homework.lcpm,v 1.163 2013/01/21 06:16:50 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -318,11 +318,13 @@ sub caparesponse_check_list { $responses->[0][-1]=$part1; $unit=&capa_formula_fix($part2); my $customunits=$LONCAPA::CAPAresponse_args{'customunits'}; - foreach my $replacement (split(/\s*\,\s*/,$customunits)) { - my ($which,$what)=split(/\s*\=\s*/,$replacement); - if ((defined($which)) && (defined($what))) { - $what=&capa_formula_fix($what); - $unit=~s/$which/\($what\)/g; + if ($customunits =~ /\S/) { + foreach my $replacement (split(/\s*\,\s*/,$customunits)) { + my ($which,$what)=split(/\s*\=\s*/,$replacement); + if ((defined($which)) && (defined($what))) { + $what=&capa_formula_fix($what); + $unit=~s/$which/\($what\)/g; + } } } } @@ -357,7 +359,7 @@ sub caparesponse_check_list { $appendunit='%'.$appendunit; } # Zero does not need a dimension - if (($element==0) && ($unit!~/\w/) && ($answerunit=~/\w/)) { + if (($element =~ /^[0\.]+$/) && ($unit!~/\w/) && ($answerunit=~/\w/)) { $appendunit=$answerunit; } # Do the math for the student if allowed @@ -814,6 +816,7 @@ sub cos { CORE::cos(shift) } sub exp { CORE::exp(shift) } sub int { CORE::int(shift) } sub log { CORE::log(shift) } +sub ln { CORE::log(shift) } sub atan2 { CORE::atan2($_[0],$_[1]) } sub sqrt { CORE::sqrt(shift) } @@ -1030,6 +1033,17 @@ sub format_significant_figures { $number = abs($number); # needed to correct for a number greater than 1 (or my $power = ($number < 1) ? 0 : 1; + if ($power && $number =~ /^\d+$/) { + my $nonzeros = $number; + $nonzeros =~ s/0+$//; + if (length($number) - length($nonzeros) > 1) { + # convert to exponential form + my $n = $sig-1; + my $numSig = sprintf('%.' . $n . 'E', $number); + # return number with sign + return $sign.$numSig; + } + } # could round up. Take the integer part of log10. my $x10 = int(log($number)/log(10)); # find number with values left of decimal pt = # of sign figs. @@ -1181,7 +1195,6 @@ sub middlename { return $middlename; } - sub lastname { my $lastname = &EXT('environment.lastname'); $lastname = '' if $lastname eq "";