"nan" v. try-catch for arithmetic

Mark Schonewille m.schonewille at economy-x-talk.com
Tue Jun 24 23:41:12 CEST 2014


Hi Graham,

If I execute (-8)^(2/3) in LiveCode 6.6.1, I get "execution error at 
line 7 (pow: range error (overflow)), char 17", i.e. an execution error 
instead of NaN.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Installer Maker for LiveCode:
http://qery.us/468

Buy my new book "Programming LiveCode for the Real Beginner" 
http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 6/24/2014 20:02, Graham Samuel wrote:
> 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