]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/agm_test.cpp
2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "math_unit_test.hpp"
12 #include <boost/lexical_cast.hpp>
13 #include <boost/core/demangle.hpp>
14 #include <boost/math/tools/agm.hpp>
15 #ifdef BOOST_HAS_FLOAT128
16 #include <boost/multiprecision/float128.hpp>
17 using boost :: multiprecision :: float128
;
20 using boost :: math :: tools :: agm
;
23 void test_gauss_constant ()
25 // http://oeis.org/A014549/constant
26 Real G_expected
= boost :: lexical_cast
< Real
>( ".83462684167407318628142973279904680899399301349034700244982737010368199270952641186969116035127532412906785" );
28 Real G_computed
= 1 / agm ( sqrt ( Real ( 2 )), Real ( 1 ));
29 if (! CHECK_ULP_CLOSE ( G_expected
, G_computed
, 2 )) {
30 std :: cerr
<< " Gauss constant not computed correctly. \n " ;
34 template < typename Real
>
40 Real expected
= agm ( scale
* a
, scale
* g
);
41 Real computed
= scale
* agm ( a
, g
);
42 if (! CHECK_ULP_CLOSE ( expected
, computed
, 2 )) {
43 std :: cerr
<< " Scaling property agm(kx,ky) = k*agm(x, y) is violated. \n " ;
47 computed
= agm ( a
, Real ( 0 ));
48 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
49 std :: cerr
<< " agm(a, 0) != 0. \n " ;
52 computed
= agm ( Real ( 0 ), Real ( 0 ));
53 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
54 std :: cerr
<< " agm(0, 0) != 0. \n " ;
58 computed
= agm ( Real ( 1 ), Real ( 1 ));
59 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
60 std :: cerr
<< " agm(1, 1) != 1. \n " ;
64 computed
= agm ( Real ( 7 ), Real ( 7 ));
65 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
66 std :: cerr
<< " agm(7, 7) != 1. \n " ;
69 // Properties I found at: https://mathworld.wolfram.com/Arithmetic-GeometricMean.html
70 // agm(x,y) = agm((x+y)/2, sqrt(xy))
71 expected
= agm ( Real ( 3 ), Real ( 1 ));
72 computed
= agm ( Real ( 2 ), sqrt ( Real ( 3 )));
73 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
74 std :: cerr
<< " agm(x, y) != agm((x+y)/2, sqrt(xy)). \n " ;
77 //computed = agm(std::numeric_limits<Real>::infinity(), Real(7));
78 //std::cout << "Computed at infinity = " << computed << "\n";
80 for ( Real x
= 0 ; x
< 1 ; x
+= Real ( 1 )/ 128 ) {
81 expected
= agm ( Real ( 1 ), sqrt ( 1 - x
* x
));
82 computed
= agm ( 1 + x
, 1 - x
);
83 if (! CHECK_ULP_CLOSE ( expected
, computed
, 0 )) {
84 std :: cerr
<< " agm(1, sqrt(1-x^2) != agm(1+x,1-x). \n " ;
92 test_gauss_constant
< float >();
93 test_gauss_constant
< double >();
94 test_gauss_constant
< long double >();
96 test_scaling
< float >();
97 test_scaling
< double >();
98 test_scaling
< long double >();
100 #ifdef BOOST_HAS_FLOAT128
101 test_gauss_constant
< float128
>();
102 test_scaling
< float128
>();
104 return boost :: math :: test :: report_errors ();