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.