Skip to main content

primitive_float_asec_pi_rational

Function primitive_float_asec_pi_rational 

Source
pub fn primitive_float_asec_pi_rational<T>(x: &Rational) -> T
where Float: PartialOrd<T>, for<'a> T: ExactFrom<&'a Float> + PrimitiveFloat,
Expand description

Computes $\operatorname{asec}(x)/\pi$, the arcsecant of a Rational measured in half-turns, returning the result as a primitive float.

This is primitive_float_asec_with_period_rational with a period of 2: see primitive_float_asec_with_period_rational for the error bounds, the special cases, and the complexity, with $u = 2$. An input of 1 gives $0.0$ and an input of $-1$ gives $1$; any $|x|<1$ gives NaN. Overflow is not possible, since $0 \leq \operatorname{asec}(x)/\pi \leq 1$.

§Worst-case complexity

$T(m) = O(m \log m \log\log m)$

$M(m) = O(m \log m)$

where $T$ is time, $M$ is additional memory, and $m$ is x.significant_bits().

§Examples

use malachite_base::num::basic::traits::{NegativeOne, One, OneHalf};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::asec::primitive_float_asec_pi_rational;
use malachite_q::Rational;

// the arcsecant is NaN inside (-1, 1)
assert!(primitive_float_asec_pi_rational::<f64>(&Rational::ONE_HALF).is_nan());
assert_eq!(
    NiceFloat(primitive_float_asec_pi_rational::<f64>(&Rational::ONE)),
    NiceFloat(0.0)
);
assert_eq!(
    NiceFloat(primitive_float_asec_pi_rational::<f64>(
        &Rational::NEGATIVE_ONE
    )),
    NiceFloat(1.0)
);
assert_eq!(
    NiceFloat(primitive_float_asec_pi_rational::<f64>(
        &Rational::from_unsigneds(5u8, 3)
    )),
    NiceFloat(0.2951672353008665)
);
assert_eq!(
    NiceFloat(primitive_float_asec_pi_rational::<f32>(
        &Rational::from_unsigneds(5u8, 3)
    )),
    NiceFloat(0.29516724)
);