pub fn primitive_float_tan_rational<T>(x: &Rational) -> Twhere
Float: PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\tan x$, the tangent of a Rational, returning the result as a primitive float.
$$
f(x) = \tan x+\varepsilon,
$$
where $|\varepsilon| < 2^{\lfloor\log_2 |\tan x|\rfloor-p}$, and $p$ is the precision of the
output (24 if T is a f32 and 53 if T is a f64).
Special cases:
- $f(0)=0$
Overflow is possible: a Rational within about $2^{-128}$ of an odd multiple of $\pi/2$ has a
tangent beyond the largest f32, and one within about $2^{-1024}$ of it beyond the largest
f64, and the result is then $\pm\infty$. The result underflows, to a subnormal or to zero,
when $x$ is tiny, since $\tan x$ is then very close to $x$; a Rational close enough to a
nonzero multiple of $\pi$ for its tangent to be subnormal would need a denominator of more than
100 bits, in which case the result is still correctly rounded.
§Worst-case complexity
$T(m, e) = O((m+e) (\log (m+e))^2 \log\log (m+e))$
$M(m, e) = O((m+e) \log (m+e))$
where $T$ is time, $M$ is additional memory, $m$ is x.significant_bits(), and $e$ is
x.floor_log_base_2_abs() (taken as 0 when it is negative or $x = 0$): for $|x| \geq 3$ the
argument is reduced modulo $2\pi$, which needs $\pi$ to about $e$ bits.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::tan::primitive_float_tan_rational;
use malachite_q::Rational;
assert_eq!(
NiceFloat(primitive_float_tan_rational::<f64>(&Rational::ZERO)),
NiceFloat(0.0)
);
assert_eq!(
NiceFloat(primitive_float_tan_rational::<f64>(
&Rational::from_unsigneds(1u8, 3)
)),
NiceFloat(0.34625354951057546)
);
assert_eq!(
NiceFloat(primitive_float_tan_rational::<f32>(
&Rational::from_unsigneds(1u8, 3)
)),
NiceFloat(0.34625354)
);
assert_eq!(
NiceFloat(primitive_float_tan_rational::<f64>(&Rational::from(10000))),
NiceFloat(0.3209711346238147)
);