Approximate equality
Is approximately equal to is a built-in operator in Raku. Unicode ≅, or the ASCII equivalent: =~=. By default it uses a tolerance of 1e-15 times the order of magnitude of the larger comparand, though that is adjustable by setting the dynamic variable $*TOLERANCE to the desired value. Probably a good idea to localize the changed $*TOLERANCE as it will affect all comparisons within its scope.
Most of the following tests are somewhat pointless in Raku. To a large extent, when dealing with Rational values, you don't really need to worry about "approximately equal to", and all of the test values below, with the exception of sqrt(2)
, are Rats by default, and exact. You would have to specifically coerce them to Nums (floating point) to lose the precision.
For example, in Raku, the sum of .1, .2, .3, & .4 is identically equal to 1.
It's also approximately equal to 1 but... ¯\_(ツ)_/¯
Output:
Last updated