.... but floats aren't promoted to integers.
It can get a bit moot:
D:\>perl -MDevel::Peek -le "$x = (2 ** 53) - 1; Dump $x; $x++; Dump $x
+; $x++; Dump $x; $x++; Dump $x;"
SV = NV(0x28e88c5a2f8) at 0x28e88c5a310
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 9007199254740991
SV = PVNV(0x28e88c24e10) at 0x28e88c5a310
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 9007199254740992
NV = 9007199254740991
PV = 0
SV = PVNV(0x28e88c24e10) at 0x28e88c5a310
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 9007199254740993
NV = 9007199254740991
PV = 0
SV = PVNV(0x28e88c24e10) at 0x28e88c5a310
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 9007199254740994
NV = 9007199254740991
PV = 0
The fact that the flags change from (NOK,pNOK) to (IOK,pIOK) suggests to me that the NV has been promoted to an IV.
Or does the fact that both the IV and NV slots have been filled suggest that it's neither an IV nor an NV. Or maybe that suggests that it's both ? ... I don't know.
Anyway, I'm not looking for an argument. It's just one of those things that I find a little mysterious.
Other differences between floats and ints is the existence of inifinity, NaN and -0
One of my beefs with Math::BigInt is that it has a NaN and an inf:
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(2.3); print $x; pr
+int ref($x);"
NaN
Math::BigInt
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / 0; print $x;
+print ref($x);"
inf
Math::BigInt
I don't regard it as all that important, but it probably shouldn't do that.
I couldn't quickly get it to provide a "-0", but I did get the following weirdness:
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / inf; print $x
+; print ref($x);"
0
Math::BigInt
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / -inf; print $
+x; print ref($x);"
-1
Math::BigInt
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.