pub fn primitive_float_atan<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\arctan x$, the arctangent of a primitive float. Using this function is more accurate
than using the default atan function or the one provided by libm.
$$ f(x) = \arctan x+\varepsilon. $$
- If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
- If $x$ is not NaN, then $|\varepsilon| < 2^{\lfloor\log_2 |\arctan x|\rfloor-p}$, where $p$ is
the precision of the output (24 if
Tis af32and 53 ifTis af64).
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\pm\infty)=\pm\pi/2$, rounded
- $f(\pm0.0)=\pm0.0$
Overflow is not possible, since the result lies in $(-\pi/2, \pi/2)$. The result is subnormal only when $x$ is, and then it is $x$ itself, since $|\arctan x - x| < |x|^3/3$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::atan::primitive_float_atan;
assert!(primitive_float_atan(f32::NAN).is_nan());
assert_eq!(
NiceFloat(primitive_float_atan(f32::INFINITY)),
NiceFloat(core::f32::consts::FRAC_PI_2)
);
assert_eq!(
NiceFloat(primitive_float_atan(f32::NEGATIVE_INFINITY)),
NiceFloat(-core::f32::consts::FRAC_PI_2)
);
assert_eq!(NiceFloat(primitive_float_atan(0.0f32)), NiceFloat(0.0));
assert_eq!(NiceFloat(primitive_float_atan(-0.0f32)), NiceFloat(-0.0));
assert_eq!(
NiceFloat(primitive_float_atan(1.0f32)),
NiceFloat(core::f32::consts::FRAC_PI_4)
);
assert_eq!(
NiceFloat(primitive_float_atan(1.0f64)),
NiceFloat(core::f64::consts::FRAC_PI_4)
);