pub const fn atan(x: Real) -> RealExpand description
Computes the arctangent of x (atan(x)).
Returns the principal value in the range [-π/2, π/2] radians.
§Special cases
atan(NaN)returnsNaNatan(±0)returns±0(preserving the sign of zero)atan(±∞)returns±π/2
§Implementation notes
This is a const fn-compatible port of the FreeBSD libm implementation
(s_atan.c). The algorithm reduces the argument based on the magnitude
of |x| and evaluates it using either a polynomial approximation or
an addition formula with precomputed constants (ATANHI/ATANLO).
Modifications for this crate:
- Adapted to the generic
Realtype (which isf64under the hood) - Made fully
const fncompatible - Removed
force_eval!(subnormal underflow side-effect, not relevant in const context) - Replaced the
i!macro with direct array indexing - Used the
.abs()method instead of thefabshelper
§Testing
This function is tested directly with:
- Sanity checks for standard angles (π/6, π/4, π/3 and their negatives)
- Special values: zero, ±infinity, NaN
It is also exercised by the full atan2 test suite (which calls atan internally).
All tests pass and produce results matching the original libm implementation.