1. An explanation of the "atom floating point" bug,
- Posted by Joel Crook <joel at MAIL.K-A.COM> Mar 19, 2000
- 411 views
--=====================_18218386==_.ALT At 01:58 PM 03/20/2000 +1200, you wrote: <SNIP!> > >...you failed to answer my >question again. jiri Last night Lewis posted some code which I modified to narrow down his problem. My code looked something like the snippet below: atom b integer a b=att - floor (att) b=b*10 a=floor(b) ? att ? b ? a If att=4.1 then b=att-floor(att) should be equal to .1 and b*10 should be equal to 1 but a is returned as 0 rather than as 1. Irv (after massaging my code) showed that att is actually att=4.09999999999999964473 and b=0.99999999999999644729 which explains why a=0 because floor rounds down to the next lower integer. So what I **think** Irv was trying to point out was an atom is really **approximation** of a float and **NOT** actually accurate as a c float of the same value. If you add .00001 to any atom you will better approximate the value of the original floating point number. Hope that is a little clearer explanation Joel H. Crook Manager, Information Services Certified Novell Administrator Microsoft Certified Professional, OS Specialist Kellogg & Andelson Accountancy Corp. 14724 Ventura Blvd. 2nd Floor Sherman Oaks, CA 91403 (818) 971-5100 --=====================_18218386==_.ALT <html><div>At 01:58 PM 03/20/2000 +1200, you wrote:</div> <div><SNIP!></div> <div>></div> <div>>...you failed to answer my</div> <div>>question again. jiri</div> <br> <div>Last night Lewis posted some code which I modified to narrow down his problem. My code looked something like the snippet below:</div> <br> <div>atom b </div> <div>integer a </div> <div>b=att - floor (att) </div> <div>b=b*10 </div> <div>a=floor(b) </div> <div>? att </div> <div>? b </div> <div>? a </div> <br> <div>If att=4.1 then b=att-floor(att) should be equal to .1 and b*10 should be equal to 1</div> <div>but a is returned as 0 rather than as 1.</div> <br> <div> Irv (after massaging my code) showed that att is actually</div> <div>att=4.09999999999999964473</div> <br> <div>and</div> <br> <div>b=0.99999999999999644729</div> <br> <div>which explains why a=0 because floor rounds down to the next lower integer.</div> <br> <div>So what I **think** Irv was trying to point out was an atom is really **approximation** of a float and **NOT** actually accurate as a c float of the same value.</div> <br> <div> If you add .00001 to any atom you will better approximate the value of the original floating point number.</div> <br> <div>Hope that is a little clearer explanation</div> <br> <br> Joel H. Crook<br> <br> Manager, Information Services<br> <font size=1>Certified Novell Administrator<br> Microsoft Certified Professional, OS Specialist<br> <br> </font><b>Kellogg & Andelson Accountancy Corp.<br> </b><font size=1>14724 Ventura Blvd. 2nd Floor<br> Sherman Oaks, CA 91403<br> (818) 971-5100<br> </font></html> --=====================_18218386==_.ALT--