Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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
Replies are listed 'Best First'.
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 romping around the Monastery: (12)
As of 2015-07-28 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls