"nan" v. try-catch for arithmetic

Graham Samuel livfoss at mac.com
Tue Jun 24 14:02:56 EDT 2014


Hi

I have a bit of code that looks for input errors where the user is supposed to write an arithmetic expression into a field. The relevant fragment looks like this

 try
  put value(fld "myField") into testResult
 catch
  answer "oops, that's not a valid real number. Try again"
  exit mouseUp
 end try
 ...

Now I input a legitimate expression like 3+sin(pi/2)

 the catch doesn't fire, as expected. If I put in something which isn't a well-formed expression, like

 ardvaark + 92

it does fire, as expected. If I put

 sqrt(-1)

that fires too. But if I put

 (-8)^(2/3)

I get a result, "nan", and the catch doesn't fire. Why not? Maybe someone can explain what the engine is doing here - or is it just an obscure bug?

TIA

Graham




More information about the use-livecode mailing list