Real (MathObject Class)
Revision as of 15:13, 2 August 2012 by Dpvc (talk | contribs) (moved MathObjects Real to Real MathObject Class: Get class name first for better alphabetical listings)
The Real Class
- The Real class implements real numbers with "fuzzy" comparison (governed by the same tolerances and settings that control student answer checking). For example,
Real(1.0) == Real(1.0000001)
will be true, whileReal(1.0) < Real(1.0000001)
will be false. Reals can be added, subtracted, and so on, and the results will still be MathObject Reals. Similarly,sin()
,sqrt()
,ln()
, and the other functions return Real objects if their arguments are Reals. For example:
Context("Numeric"); $a = Real(2); $b = $a + 5; # same as Real(7); $c = sqrt($a); # same as Real(sqrt(2));
- This allows you to compute with Reals just as you would with native Perl real numbers.
- The value
pi
can be used in your Perl code to represent the value of [math]\pi[/math]. Note that you must use-(pi)
for [math]-\pi[/math] in Perl expressions (but not in strings that will be parsed by MathObjects, such as student answers or arguments toCompute()
). For instance:
$a = pi + 2; # same as Real("pi + 2"); $b = 2 - (pi); # same as Real("2 - pi"); $c = sin(pi/2); # same as Real(1); $d = Compute("2 - pi"); # parens only needed in Perl expressions