Real (MathObject 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, while
Real(1.0) < Real(1.0000001) will be false. Reals can be created in any Context, but the
Numeric Context is the most frequently used for Reals.
Reals are created via the
Real() function, or by
Compute(). Reals can be added, subtracted, and so on, and the results will still be MathObject Reals. Similarly,
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.
pi can be used in your Perl code to represent the value of \(\pi\). Note that you must use
-(pi) for \(-\pi\) in Perl expressions (but not in strings that will be parsed by MathObjects, such as student answers or arguments to
Compute()). 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
e, for the base of the natural log, \(e\), can be used in student answers and parsed strings.
$e = Compute("e"); $p = Compute("e^2");
As with all MathObjects, you obtain an answer checker for a Real object via the
The Real class supports the common answer-checker options, and the following additional options:
||Do/don't report type mismatches if the student enters an infinity.|| |
The Real class supports the Common MathObject Methods. There are no additional methods for this class.
will add a check so that a number with decimal places is not allowed. This can be used to require students to enter values in terms of `pi` or `sqrt(2)` for example. You can also supply a Context as an argument to disallow decimals in that context:
Without a parameter, the current context is assumed.
The Real class supports the Common MathObject Properties, and the following additional ones:
|| When set, this value indicates that the real is periodic, with period given by this value. So angles might use