Re: BUG! Erratic for loop behavior

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Mon, 25 Mar 2002 11:04:25 +1000, dm31 at uow.edu.au wrote:

>an example is the 0.1 is stored as 1 x 10^-1                          
>thus the mantissa is 1 and the exponent is -1                         
>so using a 8-bit float as an example 0.1 in binary is                 
>                                                                      
>0001 and 1111(-1 in 2's complement)                                   
>                                                                      
>So storing numbers like 0.1, 0.3 and 0.01 completely accurately should
>not be a problem. It is only a problem in 'larger' decimal numbers.   
>                                                                      
>for i = 31.4 to 31.5 do... should work perfectly. Or am I just been   
>dumb?                                                                 

Possibly the latter blink  IEEE 754 floating point numbers are held in
binary math, ie <sign>*<mantissa>*2^<exponent>.

Yes, that's powers of 2, not 10. This means that 0.1 *CANNOT* be held,
the closest you get is about 0.100000000149

Read all about the only alternative I've found at
http://www2.hursley.ibm.com/decimal/

Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu