Re: floor()
- Posted by Joel Crook <joel at MAIL.K-A.COM> Mar 23, 2000
- 562 views
--=====================_113246286==_.ALT Atoms are approximations of decimal numbers a decimal number, say .1, might actually be stored as .0999999999999 10 * .0999999999999 = .999999999999 which is <1 and therefore floor would report the value as 0 We just have a long thread about this. If you want to make sure floor works add .00001 or so to the number you are using floor on and see if the results become more consistant At 10:36 PM 3/22/00 -1200, you wrote: >I'm having a problem with the floor function. >This is a (VERY VERY quickly) modified function so it will work >independently and still produce the error I am having trouble with. I'm not >worried with what I'm trying to do with my code here only show that floor() >goes haywire. > > >From this code: > >function convert(atom number) > number = number - floor(number) > ? number > for i = 1 to 5 do > > number = number * 10 > puts(1,"\n----\nCurrent Number: ") > print(1,number) > puts(1,"\nFloored Number: ") > print(1,floor(number)) > end for > > return 2 >end function > >I get these results (as copied and pasted from the DOS screen): ><start> >0.001 > >---- >Current Number: 0.01 >Floored Number: 0 >---- >Current Number: 0.1 >Floored Number: 0 >---- >Current Number: 1 >Floored Number: 0 >---- >Current Number: 10 >Floored Number: 9 >---- >Current Number: 100 >Floored Number: 99 > ><end> >Which are different yet again if I use floor() out of the function like at >the end of the .ex file. (floor(1) equals 1 all of a sudden instead of 0 as >it did inside the function). Is there somethign encrdibly simple I'm missing >here or what else can I do? > >Francis > > >Join 18 million Eudora users by signing up for a free Eudora Web-Mail >account at http://www.eudoramail.com Joel "When the code works perfectly, the program is obsolete." -- "The Gosple According to St. Murphy" --=====================_113246286==_.ALT <html><div>Atoms are approximations of decimal numbers a decimal number, say .1, might actually be stored as .0999999999999</div> <br> <div>10 * .0999999999999 = .999999999999 which is <1 and therefore floor would report the value as 0</div> <br> <div>We just have a long thread about this. If you want to make sure floor works add .00001 or so to the number you are using floor on and see if the results become more consistant</div> <br> <div>At 10:36 PM 3/22/00 -1200, you wrote:</div> <div>>I'm having a problem with the floor function.</div> <div>>This is a (VERY VERY quickly) modified function so it will work </div> <div>>independently and still produce the error I am having trouble with. I'm not </div> <div>>worried with what I'm trying to do with my code here only show that floor() </div> <div>>goes haywire.</div> <div>></div> <div>></div> <div>>From this code:</div> <div>></div> <div>>function convert(atom number)</div> <div>> number = number - floor(number)</div> <div>> ? number</div> <div>> for i = 1 to 5 do</div> <div>></div> <div>> number = number * 10</div> puts(1,"\n----\nCurrent Number: ")</div> print(1,number)</div> puts(1,"\nFloored Number: ")</div> print(1,floor(number))</div> <div>> end for</div> <div>></div> <div>> return 2</div> <div>>end function</div> <div>></div> <div>>I get these results (as copied and pasted from the DOS screen):</div> <div>><start></div> <div>>0.001</div> <div>></div> <div>>----</div> <div>>Current Number: 0.01</div> <div>>Floored Number: 0</div> <div>>----</div> <div>>Current Number: 0.1</div> <div>>Floored Number: 0</div> <div>>----</div> <div>>Current Number: 1</div> <div>>Floored Number: 0</div> <div>>----</div> <div>>Current Number: 10</div> <div>>Floored Number: 9</div> <div>>----</div> <div>>Current Number: 100</div> <div>>Floored Number: 99</div> <div>></div> <div>><end></div> <div>>Which are different yet again if I use floor() out of the function like at </div> <div>>the end of the .ex file. (floor(1) equals 1 all of a sudden instead of 0 as </div> <div>>it did inside the function). Is there somethign encrdibly simple I'm missing </div> <div>>here or what else can I do?</div> <div>></div> <div>>Francis</div> <div>></div> <div>></div> <div>>Join 18 million Eudora users by signing up for a free Eudora Web-Mail </div> <div>>account at <a href="http://www.eudoramail.com/" EUDORA=AUTOURL>http://www.eudoramail.com</a></div> <br> Joel<br> <br> "<b><i>When the code works perfectly, the program is obsolete</b></i>."<br> <div align="right"> -- "The Gosple According to St. Murphy"</html> --=====================_113246286==_.ALT--