Skip to main content

primitive_float_acsc_rational

Function primitive_float_acsc_rational 

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

Computes $\operatorname{acsc} x$, the arccosecant of a Rational, returning the result as a primitive float.

This is the correctly rounded arccosecant: the exact $\operatorname{acsc}(x)$ is rounded once, to the nearest value of the output type.

Special cases:

  • $f(x)=\text{NaN}$ for $|x|<1$, including zero

Overflow is not possible, since $|\operatorname{acsc}(x)| \leq \pi/2$. The result is subnormal, or zero, only when $|x|$ is large enough to put $1/|x|$ below the bottom of the output type’s normal range.

§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, Two};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::acsc::primitive_float_acsc_rational;
use malachite_q::Rational;

// the arccosecant is NaN inside (-1, 1)
assert!(primitive_float_acsc_rational::<f64>(&Rational::ONE_HALF).is_nan());
assert_eq!(
    NiceFloat(primitive_float_acsc_rational::<f64>(&Rational::ONE)),
    NiceFloat(1.5707963267948966)
);
assert_eq!(
    NiceFloat(primitive_float_acsc_rational::<f64>(
        &Rational::NEGATIVE_ONE
    )),
    NiceFloat(-1.5707963267948966)
);
assert_eq!(
    NiceFloat(primitive_float_acsc_rational::<f64>(&Rational::TWO)),
    NiceFloat(0.5235987755982989)
);
assert_eq!(
    NiceFloat(primitive_float_acsc_rational::<f32>(
        &Rational::from_unsigneds(5u8, 3)
    )),
    NiceFloat(0.6435011)
);