Skip to main content

primitive_float_asech

Function primitive_float_asech 

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

Computes $\operatorname{asech} x$, the inverse hyperbolic secant of a primitive float. Using this function is more accurate than using the default asech function or the one provided by libm.

$$ f(x) = \operatorname{asech} x+\varepsilon. $$

  • If $\operatorname{asech} x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\operatorname{asech} x$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \operatorname{asech} x\rfloor-p}$, where $p$ is the precision of the output (24 if T is a f32 and 53 if T is a f64).

Special cases:

  • $f(\text{NaN})=\text{NaN}$
  • $f(\pm\infty)=\text{NaN}$
  • $f(\pm0.0)=\infty$
  • $f(1)=0.0$
  • $f(x)=\text{NaN}$ if $x<0$ or $x>1$

Overflow is not possible. The result is subnormal only when $x$ is, and then it is $x$ itself, since $|\operatorname{asech} x - x| < |x|^3/2$.

§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::asech::primitive_float_asech;

assert!(primitive_float_asech(f32::NAN).is_nan());
assert!(primitive_float_asech(f32::INFINITY).is_nan());
assert!(primitive_float_asech(f32::NEGATIVE_INFINITY).is_nan());
assert_eq!(
    NiceFloat(primitive_float_asech(0.0f32)),
    NiceFloat(f32::INFINITY)
);
assert_eq!(NiceFloat(primitive_float_asech(1.0f32)), NiceFloat(0.0));
assert!(primitive_float_asech(2.0f32).is_nan());
assert_eq!(
    NiceFloat(primitive_float_asech(0.5f32)),
    NiceFloat(1.316958)
);
assert_eq!(
    NiceFloat(primitive_float_asech(0.5f64)),
    NiceFloat(1.3169578969248168)
);
assert_eq!(
    NiceFloat(primitive_float_asech(0.1f64)),
    NiceFloat(2.993222846126381)
);