WeBWorK Problems

Numerical tolerance for very small numbers

Numerical tolerance for very small numbers

by Yuncong Chen -
Number of replies: 1
Hi, I was writing this simple code snippet:

$a = 0.6**20;
Enter a: [_______]{$a}


When I input 0.6**20 as the answer, it is incorrect. I suspect this has to do with the tolerance issue. So I add 

Context('Numerics')
Context()->flags->set(tolerance=>0.0001);

The answer still is not correct.

Could you help with this problem? Thanks.



In reply to Yuncong Chen

Re: Numerical tolerance for very small numbers

by Davide Cervone -
Try
    $a = Real(0.6**20);
as this will make $a a MathObject, which will be handled better. As a Perl real, $a is converted to a string and then passed to Compute() to be converted to a MathObject, but the string version of this Perl real is 3.65616e-5 which MathObjects considers to be 3.65616 times e minus 5 rather than scientific notation (which would be 3.65616E-5).

Alternatively, you could use

    Enter a: [_________]{uc($a)}
to force the lower-case "e" to an upper-case one.

Davide