Skip to main content

primitive_float_root_u

Function primitive_float_root_u 

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

Takes the $k$th root of a primitive float. The result is correctly rounded. In particular, primitive_float_root_u(x, 3) is a correctly-rounded cube root, unlike the standard library’s cbrt.

$$ f(x,k) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |\sqrt[k]{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 if the output is subnormal).

Special cases: see Float::root_u_prec_round.

§Worst-case complexity

$T(n) = O(n^{3/2} \log n \log\log n)$

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

where $T$ is time, $M$ is additional memory, and $n$ is the precision of the output.

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::root::primitive_float_root_u;

assert_eq!(
    NiceFloat(primitive_float_root_u(27.0f64, 3)),
    NiceFloat(3.0)
);
assert_eq!(
    NiceFloat(primitive_float_root_u(2.0f64, 3)),
    NiceFloat(1.2599210498948732)
);