[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm
foxr
foxr at source.lon-capa.org
Fri Dec 14 06:17:10 EST 2012
foxr Fri Dec 14 11:17:10 2012 EDT
Modified files:
/loncom/homework/caparesponse caparesponse.pm
Log:
BZ 6577 - Ensure that computed answers all will have an appropriate number of
significant figures to pass the validation test...well actualy all user answers
get extended to the appropriate number of sigfigs so that answers will never
fail due to significance.
Students will still need to force answers into a form that has the
correct number of sigfigs (e.g for 3 sigfigs not 300 but 3.00e2)..
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.252 loncom/homework/caparesponse/caparesponse.pm:1.253
--- loncom/homework/caparesponse/caparesponse.pm:1.252 Mon Mar 5 11:50:39 2012
+++ loncom/homework/caparesponse/caparesponse.pm Fri Dec 14 11:17:09 2012
@@ -446,6 +446,7 @@
}
my (@final_awards, at final_msgs, at 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 @@
my ($result, at 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(':', at msgs));
my ($awards)=split(/:/,$result);
my @awards= split(/,/,$awards);
@@ -465,6 +465,7 @@
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 @@
$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') {
More information about the LON-CAPA-cvs
mailing list