That's not true. Floating points can represent a large range of integers exactly, and that range for a double is bigger than the range of an unsigned 32 bit int.

Type Min Max -------------------------------- -------- ----------- signed n-bit int -2^(n-1) (2^(n-1))-1 unsigned n-bit int 0 (2^n)-1 IEEE float with n-bit mantissa -2^(n+1) 2^(n+1)

Double has n=52, so 4294967295 isn't the maximum that can be held without Math::BigInt.

Type Min Max -------------------------------- ----------------- ---------------- signed 32-bit integer -2147483648 2147483647 unsigned 32-bit integer 0 4294967295 IEEE float with 52-bit mantissa -9007199254740992 9007199254740992

Demo:

$x = 2**(52+1); # For doubles, format "%.17e" will tell you if # the number is stored with no loss of precision # because log10(2**(n+1)) < 17. printf("%.17e\n\n", $x); $x -= 5; for (1..10) { printf("%f\n", $x); $x++; }
9.00719925474099200e+015 <-- That's exact. 9007199254740987.000000 9007199254740988.000000 9007199254740989.000000 9007199254740990.000000 9007199254740991.000000 9007199254740992.000000 9007199254740992.000000 <-- Least significant 9007199254740992.000000 bit dropped. 9007199254740992.000000 9007199254740992.000000

In reply to Re^2: Highest scalar = ??? by ikegami
in thread Highest scalar = ??? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.