pub fn primitive_float_agm<T>(x: T, y: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes the arithmetic-geometric mean (AGM) of two primitive floats.
$$ f(x,y) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$
- If $\text{AGM}(x,y)$ is infinite, zero, or
NaN, $\varepsilon$ may be ignored or assumed to be 0. - If $\text{AGM}(x,y)$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2
\text{AGM}(x,y)\rfloor-p}$, where $p$ is precision of the output (typically 24 if
Tis af32and 53 ifTis af64, but less if the output is subnormal).
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(-\infty,x)=f(x,-\infty)=\text{NaN}$
- $f(\infty,x)=f(x,\infty)=\text{NaN}$ if $x\neq\infty$
- $f(\infty,\infty)=\infty$
- $f(\pm0.0,x)=f(x,\pm0.0)=0.0$
- $f(x,y)=\text{NaN}$ if $x<0$ or $y<0$
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::float::NiceFloat;
use malachite_float::arithmetic::agm::primitive_float_agm;
assert_eq!(
NiceFloat(primitive_float_agm(24.0, 6.0)),
NiceFloat(13.458171481725616)
);