Re: floor()

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

--=====================_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 &lt;1&nbsp; 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>&gt;I'm having a problem with the floor function.</div>
<div>&gt;This is a (VERY VERY quickly) modified function so it will work
</div>
<div>&gt;independently and still produce the error I am having trouble
with. I'm not </div>
<div>&gt;worried with what I'm trying to do with my code here only show
that floor() </div>
<div>&gt;goes haywire.</div>
<div>&gt;</div>
<div>&gt;</div>
<div>&gt;From this code:</div>
<div>&gt;</div>
<div>&gt;function convert(atom number)</div>
<div>&gt;&nbsp;&nbsp;&nbsp; number = number - floor(number)</div>
<div>&gt;&nbsp;&nbsp;&nbsp; ? number</div>
<div>&gt;&nbsp;&nbsp;&nbsp; for i = 1 to 5 do</div>
<div>&gt;</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number = number *
10</div>
puts(1,&quot;\n----\nCurrent Number:&nbsp; &quot;)</div>
print(1,number)</div>
puts(1,&quot;\nFloored Number:&nbsp; &quot;)</div>
print(1,floor(number))</div>
<div>&gt;&nbsp;&nbsp;&nbsp; end for</div>
<div>&gt;</div>
<div>&gt;&nbsp;&nbsp;&nbsp; return 2</div>
<div>&gt;end function</div>
<div>&gt;</div>
<div>&gt;I get these results (as copied and pasted from the DOS
screen):</div>
<div>&gt;&lt;start&gt;</div>
<div>&gt;0.001</div>
<div>&gt;</div>
<div>&gt;----</div>
<div>&gt;Current Number:&nbsp; 0.01</div>
<div>&gt;Floored Number:&nbsp; 0</div>
<div>&gt;----</div>
<div>&gt;Current Number:&nbsp; 0.1</div>
<div>&gt;Floored Number:&nbsp; 0</div>
<div>&gt;----</div>
<div>&gt;Current Number:&nbsp; 1</div>
<div>&gt;Floored Number:&nbsp; 0</div>
<div>&gt;----</div>
<div>&gt;Current Number:&nbsp; 10</div>
<div>&gt;Floored Number:&nbsp; 9</div>
<div>&gt;----</div>
<div>&gt;Current Number:&nbsp; 100</div>
<div>&gt;Floored Number:&nbsp; 99</div>
<div>&gt;</div>
<div>&gt;&lt;end&gt;</div>
<div>&gt;Which are different yet again if I use floor() out of the
function like at </div>
<div>&gt;the end of the .ex file. (floor(1) equals 1 all of a sudden
instead of 0 as </div>
<div>&gt;it did inside the function). Is there somethign encrdibly simple
I'm missing </div>
<div>&gt;here or what else can I do?</div>
<div>&gt;</div>
<div>&gt;Francis</div>
<div>&gt;</div>
<div>&gt;</div>
<div>&gt;Join 18 million Eudora users by signing up for a free Eudora
Web-Mail </div>
<div>&gt;account at
<a href="http://www.eudoramail.com/"
EUDORA=AUTOURL>http://www.eudoramail.com</a></div>
<br>

Joel<br>
<br>
&quot;<b><i>When the code works perfectly, the program is
obsolete</b></i>.&quot;<br>
<div align="right">
&nbsp; -- &quot;The Gosple According to St. Murphy&quot;</html>

--=====================_113246286==_.ALT--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu