PaulStoffregen / MahonyAHRS

173 stars 60 forks source link

Incorrect invSqrt #6

Closed Nate711 closed 4 years ago

Nate711 commented 4 years ago

I was exploring the fast inverse square root and I found the included implementation to give the negative square root for some inputs such as 0.1, 0.2, and 0.4 among many others. I also timed it against 1.0/sqrt(x) and it is about 50% slower. Not sure how much you still look at this repo but though it'd be worth mentioning.

Nate711 commented 4 years ago

Ah so I was getting negative outputs since I was testing on a system with 8 byte longs. Arduinos won't have this problem. I think it remains though that 1.0/sqrt(x) is faster on my local system and could still be faster on Arduino although I need to test that.

PaulStoffregen commented 4 years ago

Which board are you using for these tests?

Nate711 commented 4 years ago

I tested on Teensy 4.0 and the performance was reversed: fast sqrt running about 50% faster.