pomettini / gba-raytracer

Simple Raytracer for the Gameboy Advance written in C
MIT License
7 stars 0 forks source link

math.c : probable error in square_root function #5

Open spocino opened 3 years ago

spocino commented 3 years ago

the square_root function has logic like so:

int i;
for (i < 0; i < 20; i++) {
// doesn't matter
}

this is almost definitely errant behavior. try i = 0; rather than i < 0;

pomettini commented 2 years ago

Thanks @spocino for pointing that out. To be fair, the code is very old and I didn't know what I was doing at that time. Unfortunately by initialising the index to zero, the behaviour of the program changes completely, due to a loss of floating point accuracy. The GameBoy Advance doesn't support floating point calculation natively, and the devkitpro implementation is (probably) doing some heavy optimisations underneath that makes undefined behaviour really hard to debug. If I would write this code again, it would 100% use integers instead, but If anyone is up for investigating about this matter, I'll be happy to accept its pull request!