pub fn primitive_float_tan<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\tan x$, the tangent of a primitive float. Using this function is more accurate than
using the default tan function or the one provided by libm.
$$ f(x) = \tan x+\varepsilon. $$
- If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
- If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\tan 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)=\text{NaN}$
- $f(\pm0.0)=\pm0.0$
Overflow is not possible: no f32 or f64 is close enough to an odd multiple of $\pi/2$
for its tangent to exceed the largest finite value (the largest tangent of an f64 is below
$2^{54}$). The result is subnormal only when $x$ is, and then it is $x$ itself: no f32 or
f64 is close enough to a nonzero multiple of $\pi$ for its tangent to be subnormal.
§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::tan::primitive_float_tan;
assert!(primitive_float_tan(f32::NAN).is_nan());
assert!(primitive_float_tan(f32::INFINITY).is_nan());
assert!(primitive_float_tan(f32::NEGATIVE_INFINITY).is_nan());
assert_eq!(NiceFloat(primitive_float_tan(0.0f32)), NiceFloat(0.0));
assert_eq!(NiceFloat(primitive_float_tan(-0.0f32)), NiceFloat(-0.0));
assert_eq!(NiceFloat(primitive_float_tan(1.0f32)), NiceFloat(1.5574077));
assert_eq!(
NiceFloat(primitive_float_tan(1.0f64)),
NiceFloat(1.5574077246549023)
);