Members
(static) E :CReal
The base of the natural logarithm.
(static) ln2 :CReal
Natural log of 2.
ln(2) = 7*ln(10/9) - 2*ln(25/24) + 3*ln(81/80)
.
(static) ONE :CReal
One.
(static) PI :CReal
The ratio of a circle's circumference to its diameter.
(static) ZERO :CReal
Zero.
Methods
(static) atan_reciprocal(n : {integer}) → {CReal}
Atan of integer reciprocal: atan(1/n).
(static) valueOf(n : {number, string}) → {CReal}
Construct a CReal from a number or string.
abs() → {CReal}
The absolute value of a constructive real. Note that this cannot be written as a conditional.
acos() → {CReal}
The trigonometric arc (incerse) cosine function.
asin() → {CReal}
The trigonometric arc (inverse) sine function.
assumeInt() → {CReal}
Produce a constructive real equivalent to the original, assuming the original was an integer. Undefined results if the original was not an integer. Prevents evaluation of digits to the right of the decimal point, and may thus improve performance.
BigIntValue() → {BigInt}
Return a BigInt which differs by less than one from the constructive real.
compareTo(x : {CReal}, r : {integer}, a : {integer})
Return 0
if x = y
to within the indicated tolerance,
-1
if x < y
, and +1
if x > y
. If x
and y
are indeed
equal, it is guaranteed that 0
will be returned. If
they differ by less than the tolerance, anything
may happen. The tolerance allowed is
the maximum of (abs(this)+abs(x))*(2**r)
and 2**a
cos() → {CReal}
The trigonometric cosine function.
exp() → {CReal}
The exponential function, that is e**this
.
floatValue() → {number}
Return a float which differs by less than one in the least represented bit from the constructive real. (We're in fact closer to round-to-nearest than that, but we can't and don't promise correct rounding.)
get_appr(precision : {integer}) → {BigInt}
Returns value / 2 ** precision
rounded to an integer.
The error in the result is strictly less than 1.
Produces the same answer as approximate
, but uses and maintains a cached approximation.
Normally not overridden, and called only from approximate
methods in subclasses.
Not needed if the provided operations on constructive reals suffice.
intValue() → {integer}
Return an integer which differs by less than one from the constructive real. Behaviour on overflow is undefined.
inverse() → {CReal}
The multiplicative inverse of a constructive real.
x.inverse()
is equivalent to CReal.valueOf(1).divide(x)
.
ln() → {CReal}
The natural (base e) logarithm.
msd(n : {integer}) → {integer}
Return ths position of the most significant digit (msd) - this version may return Number.MIN_SAFE_INTEGER
if the correct answer is < n
.
If n
is not given, it uses iter_msd
to eventually return a correct answer, unless the constructive real is zero, when it either loops forever or throws a precision overflow error.
negate() → {CReal}
The additive inverse of a constructive real.
select(x : {CReal}, y : {CReal}) → {CReal}
The real number x
if this < 0
, or y
otherwise.
Requires x = y
if this = 0
.
Since comparisons may diverge, this is often a useful alternative to conditionals.
shiftLeft(n : {integer}) → {CReal}
Multiply a constructive real by 2 ** n
.
shiftRight(n : {integer}) → {CReal}
Multiply a constructive real by 2 ** -n
.
signum(aopt : {integer}) → {integer}
Return -1
if negative, +1
if positive.
Should be called only if this != 0
.
In the 0 case, this will not terminate correctly; typically it will run until it exhausts memory.
If the two constructive reals may be equal, the one or two argument version of signum should be used.
sin() → {CReal}
The trigonometric sine function.
sqrt() → {CReal}
The square root of a constructive real.
toString(nopt : {integer}, radixopt : {integer}) → {string}
Return a textual representation accurate to n
places to the right of the decimal point.
Example
// returns "3.141"
CReal.PI.toString(3)
toStringFloatRep(n : {integer}, radix : {integer}, m : {integer}) → {StringFloatRep}
Return a textual scientific notation representation accurate to n
places to the right of the decimal point.
n
must be non-negative.
A value smaller than radix**-m
may be displayed as 0.
The mantissa
component of the result is either "0" or exactly n
digits long.
The sign
component is zero exactly when the mantissa is "0".