Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Still puzzled by floats

by jjdraco (Scribe)
on Oct 07, 2002 at 07:24 UTC ( [id://203265]=note: print w/replies, xml ) Need Help??


in reply to Re: Still puzzled by floats
in thread Still puzzled by floats

how about if you work the problem the other way.
Base 2 Base 10
----------------------------------------------
.0001 == 0/2 + 0/4 + 0/8 + 1/16 == .0625
.0010 == 0/2 + 0/4 + 1/8 + 0/16 == .125
.0011 == 0/2 + 0/4 + 1/8 + 1/16 == .1875
.0100 == 0/2 + 1/4 + 0/8 + 0/16 == .25
.0101 == 0/2 + 1/4 + 0/8 + 1/16 == .3125
.0110 == 0/2 + 1/4 + 1/8 + 0/16 == .375
.0111 == 0/2 + 1/4 + 1/8 + 1/16 == .4375
.1000 == 1/2 + 0/4 + 0/8 + 0/16 == .5
.1001 == 1/2 + 0/4 + 0/8 + 1/16 == .5625
.1010 == 1/2 + 0/4 + 1/8 + 0/16 == .625
.1011 == 1/2 + 0/4 + 1/8 + 1/16 == .6875
.1100 == 1/2 + 1/4 + 0/8 + 0/16 == .74
.1101 == 1/2 + 1/4 + 0/8 + 1/16 == .8125
.1110 == 1/2 + 1/4 + 1/8 + 0/16 == .875
.1111 == 1/2 + 1/4 + 1/8 + 1/16 == .9375

has you can see there are gaps in between the decimal numbers. The more accurate you want to get the more digits in the base 2 numbers you need. Assuming that you're working with a computer that has 32 bit registers you can only store a finite number so you may not always have enough bits to represent the fraction you want.


jjdraco
learning Perl one statement at a time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-28 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found