odd and even numbers

Paul D. DeRocco pderocco at ix.netcom.com
Tue Aug 6 00:25:32 EDT 2013


> From: Peter W A Wood
> 
> Mark Waddingham kindly explains how the engine performs 
> arithmetic in this QCC entry - 
> http://quality.runrev.com/show_bug.cgi?id=9349

That page states that arithmetic is done on 64-bit floating-point values,
which is what I always assumed, and suggests the possibility of going to
decimal in the future. I posted this response:

"Where decimal arithmetic still fails is when a quotient doesn't have a
finite representation. 1/3*3 will always be .99999... to whatever precision
the decimal arithmetic is done.

"An alternative is to define an 'epsilon' global property, with a default
value of something like 1e-15, which says how close numbers must be in order
to be considered equal. Comparing a and b could be done by actually
comparing (a-b) to (a+b)*epsilon. Allow the user to set epsilon to anything
from zero to, say, 0.1."

This works for any two positive numbers; negative numbers would work the
same, but have their sense reversed. Numbers could be compared to zero, or
to numbers of the opposite sign, by comparing their difference to epsilon.

What that page doesn't make explicit is whether even intermediate values in
calculations are converted to and from strings. Since many numeric values
are never needed in their human-readable form (loop counters being the most
obvious example), having a way to deal with binary numbers and decimal
numbers interchangeably would be a HUGE win. My suggestion was to represent
values as the combination of a number and a string, one of which may be
missing and only generated whenever something asks for it. A missing number
could be represented as a NaN, and a missing string by a null pointer.

-- 

Ciao,               Paul D. DeRocco
Paul                mailto:pderocco at ix.netcom.com 





More information about the use-livecode mailing list