toRational

Convert a floating point number to a Rational based on integer type SomeIntegral. Allows an error tolerance of epsilon. (Default epsilon = 1e-8.)

epsilon must be greater than 1.0L / long.max.

Rational!(SomeIntegral)
toRational
(
SomeIntegral
)
(,
real epsilon = 1e-8
)

Throws

Exception on infinities, NaNs, numbers with absolute value larger than long.max and epsilons smaller than 1.0L / long.max.

Examples

// Prints "22/7".
writeln(toRational!int(PI, 1e-1));

Meta