pub fn primitive_float_agm_rational<T>(x: &Rational, y: &Rational) -> Twhere
Float: PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes the arithmetic-geometric mean (AGM) of two Rationals, returning the result as a
primitive float.
$$ 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(0,x)=f(x,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_rational;
use malachite_q::Rational;
assert_eq!(
NiceFloat(primitive_float_agm_rational::<f64>(
&Rational::from_unsigneds(2u8, 3),
&Rational::from_unsigneds(1u8, 5)
)),
NiceFloat(0.3985113702200345)
);