Note that in WeBWorK, scientific notation uses an upper-case E, so you must use 1.2E-10 not perl's native 1.2e-10 (which is 1.2 times e minus 10). So it may be that somewhere internally, something is producing perl scientific notation that is then being parsed by MathObjects.
If you can send a seed that fails, perhaps I can track it down.
The issue is as I expected, the perl real is .0000518579035997391, which stringifies as 5.18579035997391e-05, which MathObjects interprets as involving the constant "e" rather than scientific notation (which it expects to be 5.18579035997391E-05).
There are several possible solutions:
- You could use
$ans = Compute(uc($ans));to force the e to be converted to upper case before
Compute()processes it. This will get the correct value to be computed.
Alternatively, you could use
$ans = Real($ans);which doesn't cause
$ansto be converted to a string first (it simply makes the perl real into a MathObject Real). That avoids the parsing and misinterpretation of the "e".
But my favorite is probably to replace
$ans = 0;by
$ans = Real(0);so that
$answill be a MathObject Real right from the start, and the remaining computations are then performed as MathObject Real operations. In this case, there is no need for the
Compute()call at all, so that can be removed.
Any of those should get you better results. Hope that does the trick for you.