14 #if !defined(GEOGRAPHICLIB_MATH_HPP)
15 #define GEOGRAPHICLIB_MATH_HPP 1
20 #if !defined(GEOGRAPHICLIB_CXX11_MATH)
28 # if defined(__GNUC__) && __cplusplus >= 201103 && \
29 !(defined(__ANDROID__) || defined(ANDROID) || defined(__CYGWIN__))
30 # define GEOGRAPHICLIB_CXX11_MATH 1
32 # elif defined(_MSC_VER) && _MSC_VER >= 1800
33 # define GEOGRAPHICLIB_CXX11_MATH 1
35 # define GEOGRAPHICLIB_CXX11_MATH 0
39 #if !defined(GEOGRAPHICLIB_WORDS_BIGENDIAN)
40 # define GEOGRAPHICLIB_WORDS_BIGENDIAN 0
43 #if !defined(GEOGRAPHICLIB_HAVE_LONG_DOUBLE)
44 # define GEOGRAPHICLIB_HAVE_LONG_DOUBLE 0
47 #if !defined(GEOGRAPHICLIB_PRECISION)
57 # define GEOGRAPHICLIB_PRECISION 2
64 #if GEOGRAPHICLIB_PRECISION == 4
65 #include <boost/version.hpp>
66 #include <boost/multiprecision/float128.hpp>
67 #include <boost/math/special_functions.hpp>
68 #elif GEOGRAPHICLIB_PRECISION == 5
72 #if GEOGRAPHICLIB_PRECISION > 3
74 #define GEOGRAPHICLIB_VOLATILE
77 #define GEOGRAPHICLIB_PANIC \
78 (throw GeographicLib::GeographicErr("Convergence failure"), false)
80 #define GEOGRAPHICLIB_VOLATILE volatile
83 #define GEOGRAPHICLIB_PANIC false
104 #if GEOGRAPHICLIB_HAVE_LONG_DOUBLE
114 #if GEOGRAPHICLIB_PRECISION == 2
122 #elif GEOGRAPHICLIB_PRECISION == 1
124 #elif GEOGRAPHICLIB_PRECISION == 3
126 #elif GEOGRAPHICLIB_PRECISION == 4
127 typedef boost::multiprecision::float128
real;
128 #elif GEOGRAPHICLIB_PRECISION == 5
129 typedef mpfr::mpreal
real;
149 static int set_digits(
int ndigits);
154 static int digits10();
160 static int extra_digits();
171 template<
typename T>
static T
pi() {
173 static const T pi = atan2(T(0), T(-1));
186 static const T degree = pi<T>() / 180;
201 template<
typename T>
static T
sq(T x)
212 template<
typename T>
static T hypot(T x, T y);
221 template<
typename T>
static T expm1(T x);
230 template<
typename T>
static T log1p(T x);
239 template<
typename T>
static T asinh(T x);
248 template<
typename T>
static T atanh(T x);
261 template<
typename T>
static T copysign(T x, T y);
270 template<
typename T>
static T cbrt(T x);
280 template<
typename T>
static T remainder(T x, T y);
291 template<
typename T>
static T remquo(T x, T y,
int* n);
300 template<
typename T>
static T round(T x);
312 template<
typename T>
static long lround(T x);
328 template<
typename T>
static T fma(T x, T y, T z);
337 template<
typename T>
static void norm(T& x, T& y)
338 { T h = hypot(x, y); x /= h; y /= h; }
352 template<
typename T>
static T sum(T u, T v, T& t);
368 template<
typename T>
static T
polyval(
int N,
const T p[], T x)
372 { T y = N < 0 ? 0 : *p++;
while (--N >= 0) y = y * x + *p++;
return y; }
384 x = remainder(x, T(360));
return x != -180 ? x : 180;
395 template<
typename T>
static T
LatFix(T x)
396 {
using std::abs;
return abs(x) > 90 ? NaN<T>() : x; }
414 template<
typename T>
static T
AngDiff(T x, T y, T& e) {
415 T t, d = AngNormalize(sum(remainder(-x, T(360)),
416 remainder( y, T(360)), t));
423 return sum(d == 180 && t > 0 ? -180 : d, t, e);
440 template<
typename T>
static T
AngDiff(T x, T y)
441 { T e;
return AngDiff(x, y, e); }
458 template<
typename T>
static T AngRound(T x);
473 template<
typename T>
static void sincosd(T x, T& sinx, T& cosx);
482 template<
typename T>
static T sind(T x);
491 template<
typename T>
static T cosd(T x);
503 template<
typename T>
static T tand(T x);
518 template<
typename T>
static T atan2d(T y, T x);
527 template<
typename T>
static T atand(T x);
541 template<
typename T>
static T eatanhe(T x, T es);
560 template<
typename T>
static T taupf(T tau, T es);
579 template<
typename T>
static T tauf(T taup, T es);
588 template<
typename T>
static bool isfinite(T x);
596 template<
typename T>
static T NaN();
610 template<
typename T>
static bool isnan(T x);
618 template<
typename T>
static T infinity();
632 template<
typename T>
static T
swab(T x) {
635 unsigned char c[
sizeof(T)];
638 for (
int i =
sizeof(T)/2; i--; )
639 std::swap(b.c[i], b.c[
sizeof(T) - 1 - i]);
647 #endif // GEOGRAPHICLIB_MATH_HPP