Log in

View Full Version : Math Errors...



Xtensity
08-07-2010, 09:02 PM
is there any way I can make a script continue even if it runs into a math error?

For instance, on my Ti-84 calculator, if the equation tries to divide by zero or something, or square root a negative, it wont refuse to continue on trying the other numbers..


This is an issue that's preventing me from progressing on my current script, since the numbers I need are scattered throughout the equation...

For instance... the working x values could be anywhere in 1-100. Say there are only 5 working x values.. the other 95 x values would return a math error and crash the script.

is there any way around this?

Cigue
08-07-2010, 09:39 PM
well, the way I'd do it is to put the following
if IntInArr(TheIntegerThatCouldFail, ArrayOfWorkingValues) then
Result := OperationThatSometimesFail;
else
Result := -1;

You could also ask more experienced scripters about try..except..finally :)

EDIT : As an example, you could put x as the integer that could fail, [2, 4, 6, 8] as working values and 2/(x-y) as the operation that could fail.

Killerdou
08-07-2010, 10:01 PM
Or you could use "try except" (should be in a tutorial somewhere)

Narcle
08-07-2010, 10:17 PM
try
your code
except
end;

like that

Xtensity
08-08-2010, 08:32 AM
Hm, I actually have absolutely no experience with try or except, would be something new to learn.

I'll go look for a tutorial.... and Cigue, if I knew the array of working values then I wouldn't have to cycle through a large number of variables to find working variables.