_Rationalize
rationalize(x) / rationalize(x, digits) — every decimal of x replaced by the rational it is closest to, with a denominator at most 10^digits (F_0170).
The way back into the exact tier, and only when asked. A Double stays visibly inexact by design (the one-way float contagion of 4.L), so a value known to be exact that arrived as a decimal — a lu factor in exact mode, a frozen consolidate result, a number read from data — had no way back. Applied silently, the conversion would relabel a computed 0.3333333333333333 as an exact 1/3; asked for, it is the reader's statement that the value is rational.
- A number becomes
_Rational.fromApproximation(d, digits): the best fraction by continued-fraction truncation, so0.3333333333333333is1/3. - A dense matrix becomes the exact
_Matrixcarrier — the reason this node lives inmatrix:scalarcannot build that carrier. - A symbolic expression keeps its shape, its decimal leaves made exact; an exact leaf is left as it is.
digitsdefaults to the fewest that make every decimal its small fraction when each looks rational (rationalizeDigits, F_0240), else to the working precision, capped at 15, the digits aDoublecarries (_Rational.DoubleReliableDigits); an explicit one must be a whole number in1 .. 15.- A value it cannot make exact declines the whole call (the owner's decision): a complex number (no exact complex carrier exists), an interval, a non-finite value. Converting the rest would leave a result in two tiers that demotes again on evaluation.
It works outside exact mode too, since it is asked for; :save groups the exact value it leaves under exact on (F_0090).
Value parameters
- digits
-
the decimal digits the approximation is good for, optional
- x
-
the expression whose decimals to convert
Attributes
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Expressionclass Objecttrait Matchableclass Any