Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Question on simple arithmetic using perl

by Anonymous Monk
on Sep 28, 2011 at 21:34 UTC ( #928430=note: print w/ replies, xml ) Need Help??


in reply to Question on simple arithmetic using perl

When the number becomes too large for an integer it is automagically promoted to a float.


Comment on Re: Question on simple arithmetic using perl
Re^2: Question on simple arithmetic using perl
by perlbaski (Sexton) on Sep 28, 2011 at 21:43 UTC
    Thank you Monk!! So does this mean its fine to use such arithmetic and not worry about whether perl can handle it correctly?
      No. A float can represent a wider range of values, but a lesser number of significant digits than an integer.

      I'm not quite sure what the question is:

      #!/usr/bin/perl -w use strict; my $all_bits_are_on = -1; printf ("all_bits => %X\n", $all_bits_are_one); my $x = $all_bits_are_on + 1; print "Adding -1 to +1 is: $x\n"; __END__ all_bits => FFFFFFFF Adding -1 to +1 is: 0

        Note that perl is actually using long and double. On 32bit double has more significant digits than long.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-11-29 03:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls