It can get tricky when you have the situation where your "int"s can hold more significant bits than your "double"s, but, of course, your doubles can deal with larger and smaller exponents than your ints. So, when you have two Perl numeric values to do an operation with, should you perform the operation as ints or as doubles?

Before 64-bit ints, the decision was simple; you do all math as doubles because the doubles can do everything the ints can do.

To counter your example, consider:

$x = 2 ** 45 + 1; $y = 2 ** 45 + 1.5; if($x + .5 == $y) {print "fine\n"} else {print "crap\n"} if($x == $y) {print "crap\n"} else {print "fine\n"} # Then $x = 1e55 + 1e44; $y = 1e55 + 2e44; # ...

Is Perl smart enough to tell that it needs to do your example with 64-bit ints but that it needs to do my examples with doubles? Obviously not. Can it be made that smart? Perhaps, but it might not be easy.

You could perlbug this to give the maintainers something to think about. But I hope you have a better appreciation for the difficultly here.

Note that you can help Perl know what you want here with a simple use integer;.

- tye        


In reply to Re: -Duse64bitint and (Cygwin) perl 5.8.7 (it's not how many bits, but how you use them) by tye
in thread -Duse64bitint and (Cygwin) perl 5.8.7 by syphilis

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.