go ahead... be a heretic | |
PerlMonks |
Re: Non-integer print output???by syphilis (Archbishop) |
on Sep 10, 2021 at 00:53 UTC ( [id://11136623]=note: print w/replies, xml ) | Need Help?? |
So why does perl convert a number that will obviously fit inside a 64 bit integer to floating point?
Firstly, note that the ** operator always returns an NV: (Maybe the question you should ask is "Why does the ** operator always return an NV ?". I don't know.) What you've displayed is that perl sometimes decides that an NV will be printed (interpolated) as an integer, and sometimes printed as a float. Obviously, non-integer NVs will always be printed as floats - no problems there. Now, perl still adheres to the utterly fuckbrained notion that, when nvtype is double, print() will never present more than 15 significant digits. And that's what you're seeing here. The NV returned by the operation 2 ** 50 contains 16 significant digits which, by this idiotic rule, must be interpolated to 15 digits. And that's what perl duly does. But if the NV contains an integer value comprising less than 16 significant digits that is in the range IV_MIN to UV_MAX (eg On a perl whose nvtype is Thre's still an absurdly low limit, but it's large enough to prevent this particular case presented here. Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|