pub fn primitive_float_sin<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\sin x$, the sine of a primitive float. Using this function is more accurate than
using the default sin function or the one provided by libm.
$$ f(x) = \sin 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 |\sin 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, since the result lies in $[-1, 1]$. 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 sine 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::sin::primitive_float_sin;
assert!(primitive_float_sin(f32::NAN).is_nan());
assert!(primitive_float_sin(f32::INFINITY).is_nan());
assert!(primitive_float_sin(f32::NEGATIVE_INFINITY).is_nan());
assert_eq!(NiceFloat(primitive_float_sin(0.0f32)), NiceFloat(0.0));
assert_eq!(NiceFloat(primitive_float_sin(-0.0f32)), NiceFloat(-0.0));
assert_eq!(
NiceFloat(primitive_float_sin(1.0f32)),
NiceFloat(0.84147096)
);
assert_eq!(
NiceFloat(primitive_float_sin(1.0f64)),
NiceFloat(0.8414709848078965)
);