Syntactic Confectionery Delight PerlMonks

### Re^3: Question on simple arithmetic using perl

by Marshall (Abbot)
 on Sep 28, 2011 at 23:08 UTC ( #928444=note: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re^4: Question on simple arithmetic using perl
by zwon (Abbot) on Sep 29, 2011 at 02:20 UTC

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

Yes, if you mean that a 64 bit floating point number has more significant bits in the mantissa than a 32 bit integer does, I agree. I leave looking up the definition of ANSI C long and double to the interested readers.

Update: I looked up what Microsoft did for storage in C. "int" and "long" are both 32 bits (other folks will assign 64 bits to a "long"). A MS "float" is 32 bits and MS "double" is 64 bits with 52 bit mantissa.

ANSI C Summary says: that an int will have at least 4 significant decimal digits and a long will have at least 9 significant decimal digits (see link for exact ANSI spec'd ranges). An int can be the same size as a long (bigger than minimum is ok).

A float has to have 6 decimal digits of precision and a double has a minimum of 10 decimal digits of precision. So a double is guaranteed to have at least one more decimal digit of precision than a long (10 vs 9).

Create A New User
Node Status?
node history
Node Type: note [id://928444]
help
Chatterbox?
 [Corion]: Hi choroba! Yeah, I brought the rain with me from Hamburg [Corion]: marto: As am I ;) And we got two interested locations for next year, Munich and Cologne maybe, which is great as well. Not Berlin though ;) [marto]: damn [choroba]: Munich is kind of close from here [Corion]: marto: Maybe in three years it'll be Berlin again ;) [marto]: in 3 years I may be able to go :P [Corion]: choroba: Both teams will ponder on whether/where/how to organize things. The workshop will be mainly in German though [Corion]: marto: Hehe ;) [marto]: my out of working hours time is very scarce at the moment

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-06-29 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (655 votes). Check out past polls.