Last updated
Was this helpful?
Last updated
Was this helpful?
Raku uses 64 bit IEEE floating points numbers which provide 53 binary digits of accuracy. If you insist on using floats your answer will be accurate in the range ± 1.1102230246251565e-16. Raku actually makes it somewhat difficult to output an exact stringified float with more than 15 digits of accuracy. It automatically rounds since it doesn't try to pretend that it is more accurate than that.
If you really DO need very high precision and accuracy, Raku has native built-in Rational number support. Rationals are the ratio of two integers, and are always exact. Standard Rats are limited to 64 bits of precision in the denominator. On overflow, they will downgrade to a float (Num). FatRats have unlimited denominators.
There is no need to load any external libraries or force the use of Rats. Unless you force it otherwise, decimal number are always stored as Rats as long as they will fit within the denominator limit.
You can see the two integers making up the ratio of a Rat (or FatRat) using the .nude method (numerator, denominator).
Rats and FatRats by default stringify to a fixed number of places for non-terminating fractions and the same number of digits as the denominator for terminating fractions. If you need more control over stringification, load the module Rat::Precise for configurable stringification. Rat::Precise only affects stringification, not calculation. Calculations are always done at full (exact) precision.