logicalTrunc

Eric Chatonet eric.chatonet at sosmartsoftware.com
Tue Feb 12 03:17:57 EST 2008


Hi Hugh,

You are right :-)
Not correct with calculations...

Le 12 févr. 08 à 08:20, FlexibleLearning at aol.com a écrit :

> Eric wrote:
>> function logicalTrunc n
>>    if n is  not a number then return "NAN"
>>    return n - (n mod 1)
>>  end logicalTrunc
>
> Sorry, Eric... MOD suffers from the same same floating point issue   
> as TRUNC:
>
> get (36 - 34.1) *  100   --> 190, good
>         put it - (it MOD 1)    --> 189, bad
>
>
> Avoiding them obtains the expected answer:
>
>         get logicalTrunc ((36 - 34.1) *  100) --> 190, good
>
>         function logicalTrunc  n
> if n is not a number then  return "NAN"
> set the  itemDel to "."
> return item 1  of n
> end logicalTrunc # by Kay C  Lan
>
>         or
>
> function  logicalTrunc n
> if n is  not a number then return  "NAN"
> get offset(".",  n)
>           if it > 0  then
> delete char it to -1 of n
> end if
> return  n
> end logicalTrunc # by  Richard Gaskin
>
>
> Bottom line:
>
>         Use TRUNC and MOD with  single numbers, not with calculations
>
> /H



Best regards from Paris,
Eric Chatonet.
----------------------------------------------------------------
Plugins and tutorials for Revolution: http://www.sosmartsoftware.com/
Email: eric.chatonet at sosmartsoftware.com/
----------------------------------------------------------------





More information about the use-livecode mailing list