pub fn primitive_float_rational_pow<T>(x: &Rational, y: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Raises a Rational to a primitive float power, returning a primitive float.
The result is correctly rounded to the nearest value. Unlike a primitive-float base, a
Rational base may lie outside the primitive float’s exponent range or so close to 1 that its
logarithm is unrepresentable; both are handled exactly, by working with the base as an exact
Rational.
$$ f(x,y) = x^y+\varepsilon. $$
- If $x^y$ is infinite, zero, or
NaN, $\varepsilon$ may be ignored or assumed to be 0. - If $x^y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\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,\pm0.0)=1.0$ for any $x$
- $f(1,y)=1.0$ for any $y$, even
NaN - $f(x,\text{NaN})=\text{NaN}$ otherwise
- $f(x,\infty)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
- $f(x,-\infty)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
- $f(\pm1,\pm\infty)=1.0$
- $f(-1,y)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
- $f(0,y)=0.0$ if $y>0$, and $\infty$ if $y<0$; a
Rationalzero is unsigned, so the results take positive signs - $f(x,y)=\text{NaN}$ if $x<0$ and $y$ is finite and not an integer
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_rational_pow;
use malachite_q::Rational;
assert_eq!(
NiceFloat(primitive_float_rational_pow(
&Rational::from_unsigneds(3u32, 2u32),
2.5
)),
NiceFloat(2.7556759606310752)
);
assert_eq!(
NiceFloat(primitive_float_rational_pow(
&Rational::from_unsigneds(9u32, 4u32),
0.5
)),
NiceFloat(1.5)
);
assert!(
primitive_float_rational_pow::<f64>(&-Rational::from_unsigneds(3u32, 2u32), 0.5).is_nan()
);