Skip to main content

primitive_float_root_u_rational

Function primitive_float_root_u_rational 

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

Takes the $k$th root of a Rational, returning the result as a primitive float. The result is correctly rounded.

$$ 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_rational_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_rational;
use malachite_q::Rational;

assert_eq!(
    NiceFloat(primitive_float_root_u_rational::<f32>(
        &Rational::from_signeds(8, 27),
        3
    )),
    NiceFloat(0.6666667)
);