pub fn primitive_float_pow_u<T>(x: T, n: u64) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Raises a primitive float to the power of a u64, returning a primitive float.
The result is correctly rounded to the nearest value.
$$ f(x,n) = x^n+\varepsilon. $$
- If $x^n$ is infinite, zero, or
NaN, $\varepsilon$ may be ignored or assumed to be 0. - If $x^n$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p}$, where
$p$ is the precision of the output (typically 24 if
Tis af32and 53 ifTis af64, but less if the output is subnormal).
Special cases:
- $f(x,0)=1.0$ for any $x$, even
NaN - $f(1.0,n)=1.0$
- $f(\text{NaN},n)=\text{NaN}$ if $n \neq 0$
- $f(-1.0,n)=1.0$ if $n$ is even, and $-1.0$ if $n$ is odd
- $f(\infty,n)=\infty$ if $n>0$
- $f(-\infty,n)=\infty$ if $n$ is positive and even, and $-\infty$ if $n$ is odd
- $f(0.0,n)=0.0$ if $n>0$
- $f(-0.0,n)=0.0$ if $n$ is positive and even, and $-0.0$ if $n$ is odd
If the result overflows, $\pm\infty$ is returned, and if it underflows, $\pm0.0$ is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::pow::primitive_float_pow_u;
assert_eq!(NiceFloat(primitive_float_pow_u(3.0, 5)), NiceFloat(243.0));
assert_eq!(NiceFloat(primitive_float_pow_u(2.0, 10)), NiceFloat(1024.0));
assert_eq!(NiceFloat(primitive_float_pow_u(-2.0, 3)), NiceFloat(-8.0));