Strange math behaviour... could someone explain this ?

Mark Waddingham 36degrees at runrev.com
Sun Oct 9 09:20:54 EDT 2005


> Computers are the servants of humans, not the other way around.

Computers only do precisely what they are told and, unfortunately, it is
not always possible to instruct them to do things in a single way that
satisfies everyone 100% of the time.

Indeed, in cases where you might have a dozen different uses for a
particular 'slave', you must compromise and ensure that you equip it
with just enough so that it enables itself to be used in all of those
ways. Unfortunately, sometimes this means that its masters need to know
a little more about what they are doing than they would like so that
they can instruct such a 'slave' appropriately.

Of course, over time one learns more about what tasks the 'slave' can be
instructed to do to ease the burden on the masters and so the 'slave'
can be augmented with additional tasks...

> In human logic, this:
> 
>    trunc((36-34.2)*100)
> 
> ...is evaluated in three steps:
> 
> 1. 36-34.2 = 1.8
> 2. 1.8 * 100 = 180
> 3. truncate 180 = 180
> 
> Math is a human tool devised for the benefit of humans.  Parentheses 
> have a specific meaning which breaks down operations into an explicit 
> order of operations.

This has nothing to do with parantheses or the order of evaluation, but
is entirely down to assumptions being made about the nature of the trunc
function - which is certainly due to a lack of explicit documentation
about its nature.

I think what this entire thread comes down to is that Revolution needs a
more intuitive 'integer part' function. I'd be reticent to alter the
semantics of trunc as it stands because:
  1) It has been in the engine for an age
  2) All other programming environments offer a function that does
*exactly* the same thing
  3) It has a deeply ugly name quite fitting of it's raw nature.

The semantics of such a new function would attempt (heuristically) to
account for the error present in floating-point arithmetic and in so
doing would function more inline with human intuition.

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