Skip to main content

primitive_float_sinh_cosh

Function primitive_float_sinh_cosh 

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

Computes $\sinh x$ and $\cosh x$, the hyperbolic sine and cosine of a primitive float, together. The results are correctly rounded.

The results are those of primitive_float_sinh and primitive_float_cosh, but they share a single exponential, so this is faster than the two calls when both values are needed.

$$ f(x) = (\sinh x+\varepsilon_s, \cosh x+\varepsilon_c). $$

  • If a result is infinite, zero, or NaN, its $\varepsilon$ may be ignored or assumed to be 0.
  • If the results are finite and nonzero, then $|\varepsilon_s| < 2^{\lfloor\log_2 |\sinh x|\rfloor-p}$ and $|\varepsilon_c| < 2^{\lfloor\log_2 \cosh x\rfloor-p}$, where $p$ is the precision of the output (typically 24 if T is a f32 and 53 if T is a f64, but less for a subnormal hyperbolic sine).

Special cases:

  • $f(\text{NaN})=(\text{NaN},\text{NaN})$
  • $f(\infty)=(\infty,\infty)$
  • $f(-\infty)=(-\infty,\infty)$
  • $f(\pm0.0)=(\pm0.0,1.0)$

Overflow is possible: an x of large magnitude gives infinite results. Neither result underflows. The hyperbolic sine is subnormal only when $x$ is, and then it is $x$ itself.

§Worst-case complexity

Constant time and additional memory.

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::sinh_cosh::primitive_float_sinh_cosh;

let (s, c) = primitive_float_sinh_cosh(f32::NAN);
assert!(s.is_nan());
assert!(c.is_nan());

let (s, c) = primitive_float_sinh_cosh(-0.0f32);
assert_eq!(NiceFloat(s), NiceFloat(-0.0));
assert_eq!(NiceFloat(c), NiceFloat(1.0));

let (s, c) = primitive_float_sinh_cosh(1.0f32);
assert_eq!(NiceFloat(s), NiceFloat(1.1752012));
assert_eq!(NiceFloat(c), NiceFloat(1.5430807));

let (s, c) = primitive_float_sinh_cosh(-1.0f64);
assert_eq!(NiceFloat(s), NiceFloat(-1.1752011936438014));
assert_eq!(NiceFloat(c), NiceFloat(1.5430806348152437));

let (s, c) = primitive_float_sinh_cosh(1000.0f64);
assert_eq!(NiceFloat(s), NiceFloat(f64::INFINITY));
assert_eq!(NiceFloat(c), NiceFloat(f64::INFINITY));