Skip to main content

primitive_float_atan_with_period

Function primitive_float_atan_with_period 

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

Computes $\arctan(x)u/(2\pi)$, the arctangent of a primitive float measured in $u$ths of a turn (so that u = 360 gives degrees).

$$ f(x,u) = \arctan(x)u/(2\pi)+\varepsilon. $$

  • If $x$ is NaN or zero, $u = 0$, or $|x|$ is 1 or infinite, $\varepsilon$ may be ignored or assumed to be 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |\arctan(x)u/(2\pi)|\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},u)=\text{NaN}$
  • $f(\pm\infty,u)=\pm u/4$, a quarter turn
  • $f(\pm0.0,u)=\pm0.0$
  • $f(x,0)=\pm0.0$, with the sign of $x$, so that the function stays odd
  • $f(\pm1,u)=\pm u/8$, an eighth of a turn

Overflow is not possible, since $|f(x,u)| < u/4 < 2^{62}$. The result is subnormal, or zero, only when $x$ is tiny and $u$ is small, since the result is about $xu/(2\pi)$ there.

§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::atan::primitive_float_atan_with_period;

assert!(primitive_float_atan_with_period(f32::NAN, 360).is_nan());
// an infinite input is a quarter turn
assert_eq!(
    NiceFloat(primitive_float_atan_with_period(f32::INFINITY, 360)),
    NiceFloat(90.0)
);
assert_eq!(
    NiceFloat(primitive_float_atan_with_period(
        f32::NEGATIVE_INFINITY,
        360
    )),
    NiceFloat(-90.0)
);
// an input of 1 is an eighth of a turn
assert_eq!(
    NiceFloat(primitive_float_atan_with_period(1.0f32, 360)),
    NiceFloat(45.0)
);
assert_eq!(
    NiceFloat(primitive_float_atan_with_period(2.0f32, 360)),
    NiceFloat(63.434948)
);
assert_eq!(
    NiceFloat(primitive_float_atan_with_period(2.0f64, 360)),
    NiceFloat(63.43494882292201)
);