Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Exploring IEEE754 floating point bit patterns.

by pryrt (Abbot)
on Jun 23, 2016 at 15:10 UTC ( [id://1166384]=note: print w/replies, xml ) Need Help??


in reply to Exploring IEEE754 floating point bit patterns.

I know I'm resurrecting an ancient thread, but I was looking at this again while thinking about my Expand.pm module: I think the counts you showed were off: of the 2**64 = 18e18 combinations of the 64bit value, you listed 18e15 non-normalized numbers, of which 9e15 were denormalized, 18e18 were signaling NaN, and 18e18 were quiet NaN, which didn't quite add up right. :-) Here are my tallies:

Zeroes plus denormals are all the combinations that have the 11 exponent bits of 000_0000_0000, that is:

*_000_0000_0000_****_****_****_****_****_****_****_****_****_****_ +****_****_**** => 2^53 = 9,007,199,254,740,992 => #zeroes = 2 => #denormals = 9,007,199,254,740,990 => #positive = 4,503,599,627,370,495 => #negative = 4,503,599,627,370,495

Infinities plus NaNs take all combinations that have the 11 exponent bits of 111_1111_1111, that is:

*_000_0000_0000_****_****_****_****_****_****_****_****_****_****_ +****_****_**** => 2^53 = 9,007,199,254,740,992 => #infinities = 2 => #NaNs= 9,007,199,254,740,990 => #signalling = 4,503,599,627,370,495 => #quiet = 4,503,599,627,370,495

That should leave 2**64 - 2*(2**53) for normalized numbers:

18,446,744,073,709,551,616 = #64bit values - 18,014,398,509,481,984 = #zeroes + #infinities + #denormal + # +NaN = 18,428,729,675,200,069,632 = #normalized numbers

Confirming 2**52, 2**53, 2**54, 2**64, and 2**64 - 2**54 :

cmd.exe> perl -MMath::BigInt -E "$b = Math::BigInt->new(2); my $x = ($ +b**$ARGV[0]); $x =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g ; say $x" 52 4,503,599,627,370,496 cmd.exe> perl -MMath::BigInt -E "$b = Math::BigInt->new(2); my $x = ($ +b**$ARGV[0]); $x =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g ; say $x" 53 9,007,199,254,740,992 cmd.exe> perl -MMath::BigInt -E "$b = Math::BigInt->new(2); my $x = ($ +b**$ARGV[0]); $x =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g ; say $x" 54 18,014,398,509,481,984 cmd.exe> perl -MMath::BigInt -E "$b = Math::BigInt->new(2); my $x = ($ +b**$ARGV[0]); $x =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g ; say $x" 64 18,446,744,073,709,551,616 cmd.exe> perl -MMath::BigInt -E "$b = Math::BigInt->new(2); $p1 = Math +::BigInt->new($ARGV[0]); $p2 = Math::BigInt->new($ARGV[1]); $x = $b** +$p1; $y = $b**$p2; $z = $x-$y; say join qq|\n|, map { s/(\d{1,3}?)(?= +(\d{3})+$)/$1,/g; $_ } $x, $y, $z;" 64 54 18,446,744,073,709,551,616 18,014,398,509,481,984 18,428,729,675,200,069,632

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-23 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found