tarcieri / micromath

Embedded Rust arithmetic, 2D/3D vector, and statistics library
Apache License 2.0
401 stars 21 forks source link

acos() returns a value outside of [0,pi] for negative values and panics on zero #74

Closed timboldt closed 3 years ago

timboldt commented 3 years ago

I passed in a slightly negative value, -0.09557510558, and got a very unexpected value near -1.5. The correct output should be near +1.6 (i.e. close to +90 degrees).

I had intended to pass in 0.0, with an expected output of +1.57 (+90 degrees), but when I tried that, I got a panic. (The approximation is dividing by zero.)

There are hints in the associated StackExchange article (referenced in acos.rs) that suggest a fix for this.

timboldt commented 3 years ago

If you think it would be useful, I could add some table-driven tests for some of the functions, like acos(), that don't have them.

tarcieri commented 3 years ago

@timboldt absolutely, that'd be great!

FYI, I'm about to land a pretty major refactor (#75), so maybe give me an hour or so. NM, just landed it! Go for it.

timboldt commented 3 years ago

https://github.com/tarcieri/micromath/pull/79