Strange math behaviour... could someone explain this ?

Mark Waddingham 36degrees at runrev.com
Sun Oct 9 16:19:37 EDT 2005


Hi Mark,

What you have illustrated is precisely why JB was experiencing this
problem in the first place (and precisely why most languages do not try
to do anything clever when asked to truncate floating-point numbers).

Due to the need to approximate floating-point numbers with a finite
precision, the majority of numbers will *always* deviate from the ideal
number by a finite amount.

However, when you are doing calculations you always know something the
computer does not know: how precise your ideal calculations are. As I
went to say further on in my post, the epsilon value you need will
depend on the circumstance.

In the case you give, you have just given an arbitrary number with no
context, therefore it makes no sense to talk about epsilon values as
there is no way to determine what the maximum deviation from the
expected result could be.

In the case you give, if the number
  179.99999999999971578291
has resulted from a calculation with a maximum error of 1e-7, then it
actually means that the *true* answer lies somewhere in the interval
  (179.99999989999972171972, 180.00000009999970984609)

At which point a truncation of 180 seems like a much more sensible
answer than 179 as it is within the range of error of the calculation -
but then, this is me only guessing at why you wanted to truncate that
value in the first place :o)

Warmest Regards,

Mark.

------------------------------------------------------------------
 Mark Waddingham ~ 36degrees at runrev.com ~ http://www.runrev.com
       Runtime Revolution ~ User-Centric Development Tools




More information about the use-livecode mailing list