I have a problem with the answer evaluator
num_cmp( $ans, "tol"=>".0001")
The correct answer is $ans = 1.9604; a student answers "1.9605" and it is marked wrong. However, "1.9603" is marked correct. My understanding of the "tol" parameter is that it is an absolute tolerance: the answer must be within "tol" of the correct answer to be marked correct. Here, however, |1.9604 - 1.9605| = |1.9604 - 1.9603| = .0001, so shouldn't both of these be marked correct (or both marked wrong)?
Your surmise is what I was thinking was happening, but couldn't see how that would be the case given how the answer is being generated.
The correct answer is generated approximately as follows
$ans = [assorted numerical calculations];
$ans = round(10000*$ans)/10000;
It's actually part of a Runge-Kutta problems for an ODE course, so the [assorted numerical calculations] are the calculations to generate the successive RK approximation. If it's useful I can include those, but I don't think they matter for this discussion.
You can see this by executing the following:
perl -e 'print 1.9605-1.9604 , " <=> " , 1.9604-1.9603, "\n"'which produces the output
0.000100000000000211 <=> 9.99999999997669e-05Note that the first difference is slightly greater than .0001 while the second is slightly less than .0001.
There is really nothing you can do about this; it's just the way real floating-point reals work. You can't count on values at the edge of the allowed precision to work accurately, as nearly all decimal numbers have conversion errors. (Since 10 is not a power of 2, the conversion between the two bases rarely produce finite representations in both, and so there will be loss when one representation is truncated or rounded).