I am surprised by what these commands do in the preamble of a problem file:
Context("Numeric"); $pi = 4*atan(1); $s1 = sprintf("%18.15f",$pi); $s2 = sprintf("%18.15f", pi); $s3 = sprintf("%18.15f",$pi-pi);
Displaying the values of the string variables defined here produces this:
$s1 = 3.141592653589793 $s2 = 3.141590000000000 $s3 = 0.000000000000000
The first one shows that Perl itself handles floating-point calculations as expected; the second shows that the built-in variable "pi" provided by WeBWorK has much lower precision than Perl's native calculations; and the third calls for a re-interpretation of the subtraction symbol that I find quite uncomfortable.
Two questions arise.
- Why does "$pi-pi" evaluate to 0 here?
- Can I do something at the level of an individual .pg file to compel WeBWorK to keep more precision in its floating-point types and associated objects (like "Formula"s)?
I address WeBWorK through an institutionally-provided installation of Version 2.15, so remedies that do not require intervention at the server level (where I don't have access) would be especially welcome. Thanks!