Test integerness
In Raku, all numeric types have a method called narrow
, which returns an object with the same value but of the most appropriate type. So we can just check if that object is an Int
. This works even with floats with large exponents, because the Int
type supports arbitrarily large integers.
For the extra credit task, we can add another multi candidate that checks the distance between the number and it's nearest integer, but then we'll have to handle complex numbers specially.
Output:
Last updated