--- loncom/homework/caparesponse/caparesponse.pm 2012/03/05 11:50:39 1.252 +++ loncom/homework/caparesponse/caparesponse.pm 2012/12/14 11:17:09 1.253 @@ -446,6 +446,7 @@ sub check_submission { } my (@final_awards,@final_msgs,@names); + # $Apache::lonxml::debug = 1; # DEBUG foreach my $name (keys(%answer)) { &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} })); @@ -456,7 +457,6 @@ sub check_submission { my ($result,@msgs) = &Apache::run::run("&caparesponse_check_list()",$safeeval); &Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0)); - &Apache::lonxml::debug('msgs are '.join(':',@msgs)); my ($awards)=split(/:/,$result); my @awards= split(/,/,$awards); @@ -465,6 +465,7 @@ sub check_submission { push(@final_msgs,$msg); push(@names,$name); } + # $Apache::lonxml::debug = 0; # DEBUG my ($ad, $msg, $name) = &Apache::inputtags::finalizeawards(\@final_awards, \@final_msgs, \@names,1); @@ -784,6 +785,19 @@ sub end_numericalresponse { $ans.=" $cleanunit"; } } + # + # The computer's response must be cast in a form that + # ensures it has sufficient significant figures. + # the only way to do this is to sprintf it into scientific notation + # due to the ambiguity of trailing zeros. + # See Bug 6577 + # + my ($sigMax, $sigmin) = &get_sigrange($Apache::inputtags::params{'sig'}); + my $sigfigs = $sigMax-1; + + for (my $i = 0; $i < scalar @$response; $i++) { + $response->[$i] = sprintf('%.' . $sigfigs . 'e', $response->[$i]); + } my ($ad,$msg)=&check_submission($response,$partid,$id,$tag, $parstack,$safeeval); if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {