Comparing very long numeric strings

Michael J. Lew michaell at unimelb.edu.au
Tue Mar 16 23:01:13 EST 2004


Probably some sort of numeric overflow condition. I don't know 
exactly what, but here's a possibly related observation:
A long string of digits can be a number beyond at least 1000 places 
but you can't necessarily use them.

Try these little tests:
put (10^308) is a number    --true
put (10^309) is a number   --false
put 1*(10^308) is a number   --true
put 2*(10^308) is a number  --Error description: Operators *: range 
error (overflow)

Make a button with this script to see that 1 followed by 1000 zeros 
is a number but you can't do maths with it:
on mouseUp
   set the hilite of me to true
   put 1 into tint
   put 0 into kount
   repeat 1000
     add 1 to kount
     put kount
     put tint & "0" into tint
     put log10(tint) into myNum
     if tint is not a number then
       put "integer failed" && kount
       exit repeat
     end if
   end repeat
   put (tint +1) is a number
   set the hilite of me to false
end mouseUp

Your workaround seems to be the ticket...

Jim Lyons wrote:
>I had very unexpected results from a fairly simple script. I have a
>long string of 1s and 0s in a variable representing the states of cells
>in a cellular automata simulation. There can be more than ten thousand
>cells. To detect when the CA is no longer changing, I save this string
>each cycle, then compare it with the string representing the next
>state:
>
>      [ code to compute next state ]
>      if nextState = curState then StopCA
>      put nextState into curState
>      showCA
>
>Sometimes this worked, but many times the CA would stop before it
>should have; other times it would not stop when it should. I checked
>the code carefully, looked at the variables in the debugger, and looked
>in the docs for clues. Finally, I wondered if there could be a
>difference between numeric and string comparison, so I tried changing
>the comparison above to:
>
>      if "z"&nextState = "z"&curState then StopCA
>
>Surprisingly (to me) this fixed the problem. I've already digressed too
>long on this so can't look into it any more right now. Just wanted to
>put this tidbit in our archives, and see if anyone who knows more than
>I is not surprised by this, or can correct me if my analysis is
>wrong...

-- 
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: michaell at unimelb.edu.au
**


More information about the use-livecode mailing list