Stack overflow in Math.multiply .14

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Stack overflow in Math.multiply .14

insan-e
I've started working on Math.jack and implemented all of the functions. However, the last test fails, namely

let r[13] = Math.abs(-32767);      // 32767

I tried to debug it, and I found that it I can't negate a number bigger than 24575.
A simple line like

do Output.printInt(-24575);

throws an error "Stack overflow in Math.multiply.14"..
What could be the cause?
Reply | Threaded
Open this post in threaded view
|

Re: Stack overflow in Math.multiply .14

cadet1620
Administrator
 Math.multiply() and Math.divide() are fundamental and are used by a lot of the other OS classes.  Output uses them to position and draw characters and String uses them for integer to string conversion.

This means that until you get Math passing MathTest, all the I/O calls will likely fail.

Load MathTest.tst into the VMEmulator and set a breakpoint, name = "currentFunction" (use the dropdown) and value = "Math.abs". Run the test and you will be able to step through it and see what's going wrong with abs(-32767).

Also useful are breakpoints like name = "line", value = "Math.abs.0" if you want to stop after a particular line in a function is executed.

--Mark