It depends on what you think the "complicated" number is.
Many decimal fractions can't be represented without a tiny loss as binary floats.°
But print rounds the last digit(s) before output so it'll look accurate at first,
DB<80> $x = 1.100000000000; DB<81> print $x 1.1
even if it's internal representation is flawed.°
DB<84> printf '%0.16f', 1.1 1.1000000000000001
but as soon as the rounding error exceeds print's tolerance, you'll get bitten
DB<82> $x += 1.1 for 1..55; DB<83> print $x 61.6000000000001
So, yes you can mostly rely on it, if the number was never part of arithmetic operations which accumulated rounding errors.
BUT you should know that the print wasn't just cutting off trailing zeros but also rounding to achieve this.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
It's an inherent problem of floating point arithmetic. Not many languages offer alternatives to avoid this "flaw" with rational numbers. (Raku seems to be one of the exceptions here). NB: But this won't help with non-rational numbers like Pi or sqrt(2).
In reply to Re: Perl 5 numeric type and simplifications (updated)
by LanX
in thread Perl 5 numeric type and simplifications
by pango
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |