Troubles with inequality

Kay C Lan lan.kc.macmail at gmail.com
Sat Feb 7 02:38:07 CET 2015


On Thu, Feb 5, 2015 at 7:02 AM, Graham Samuel <livfoss at mac.com> wrote:

> Thanks Jacque, a gold mine of information as usual. But it’s pretty
> obscure, isn’t it? All this started for me because I wanted to test if two
> numbers were equal, knowing that they probably weren’t exactly equal to the
> last decimal place but nevertheless were ‘engineering equal’ as it were -
> say to six places of decimals. So I tried to truncate them to that length
> and then compare them. More fool me. But now I think I know what should be
> done, thanks to you - and to everyone else who replied.
>
> Graham
>

Why not a simple: (in the multline msg box)

put "1.99999999901" into a
put "1.99999999902" into b
put a = b  into msg
put cr & (char 1 to 8 of a = char 1 to 8 of b) after msg
put "1.0" into a
put "1.0000000001" into b
put cr & (a = b) after msg
put cr & (char 1 to 8 of a = char 1 to 8 of b) after msg

8 characters is to 6 decimal places and the fact that LC automatically
casts to numbers where it can nicely solves the problem that although
string 1.0 <> 1.000000 in your case you are interested in the numeric value
so you get the correct answer.

LCs chunking capabilities are brilliant, we sometimes just need to remember
that a number is a word in LC, and words have characters, and characters
can be compared. The nice thing about LC is when presented with a number
Cat you don't have to skin it with only number solutions; you can engineer
any result you want ;-)


More information about the use-livecode mailing list