It probably should be mentioned at this point (before the inquest
starts) that the reason why libm is the way it is is several fold:
1) libm is required to deliver correct results (not sorta correct)
including edge cases, with the correct rounding mode, exceptions, etc.
This is expensive because it involves configuring the
FPSCR
and often quite a bit of branching to deal with edge cases not covered
by the general purpose algorithm.
And how! The Darwin source libm-test.c includes the torture tests that
the libm/libmx atan2 has presumably passed. Here's a small extract:
Beware: The tests might fail for any of the following reasons:
- Tests are wrong
- Functions are wrong
- Floating Point Unit not working properly
- Compiler has errors