Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trapping owerflow errors in your own interpreter
#11
Do a multiplication check in every multiplication done in the pow function.

M = M1 * M2 will overflow if M2 > 32767\M1

Generally:

A (operator) B will overflow if B > [max numer] (inv. operator) A.

Operator: +, Inv. operator: -
Operator: *, Inv. operator: /
Operator: pow, Inv. operator: nth root
...
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#12
I can't test the number without making them VAL()?

(The numbers are stored as strings, ex: "289347")

The largest number you can pass to val is "1.xxxxxxxxxxxxxxD+308" witch is large, but still, if a stupid-user enters 4D+800 then it shouldn't crash, it should report the error, and my interpreter should remain in control.

So, I have 2 options:
1)
Code:
ON ERROR GOTO x
x:
IF ERR=6 THEN 'overflow
[...] 'dostuff
END IF
and 2)
Make my own ASM Math lib, that doesent crash on overflow, or find one already existing.
Reply
#13
Quote:I can't test the number without making them VAL()?

(The numbers are stored as strings, ex: "289347")

The largest number you can pass to val is "1.xxxxxxxxxxxxxxD+308" witch is large, but still, if a stupid-user enters 4D+800 then it shouldn't crash, it should report the error, and my interpreter should remain in control.

you can parse the string, look for the D+ substring, look the number behind, and make sure that it is <800.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)