14# pragma warning (disable: 4127)
23 "Bad value of precision");
27#if GEOGRAPHICLIB_PRECISION != 5
28 return numeric_limits<real>::digits;
30 return numeric_limits<real>::digits();
35#if GEOGRAPHICLIB_PRECISION != 5
38 mpfr::mpreal::set_default_prec(ndigits >= 2 ? ndigits : 2);
44#if GEOGRAPHICLIB_PRECISION != 5
45 return numeric_limits<real>::digits10;
47 return numeric_limits<real>::digits10();
53 digits10() > numeric_limits<double>::digits10 ?
54 digits10() - numeric_limits<double>::digits10 : 0;
58 using std::hypot;
return hypot(x, y);
62 using std::expm1;
return expm1(x);
66 using std::log1p;
return log1p(x);
70 using std::asinh;
return asinh(x);
74 using std::atanh;
return atanh(x);
78 using std::copysign;
return copysign(x, y);
82 using std::cbrt;
return cbrt(x);
86 using std::remainder;
return remainder(x, y);
90 using std::remquo;
return remquo(x, y, n);
94 using std::round;
return round(x);
98 using std::lround;
return lround(x);
102 using std::fma;
return fma(x, y, z);
118 static const T z = 1/T(16);
119 if (x == 0)
return 0;
122 y = y < z ? z - (z - y) : y;
123 return x < 0 ? -y : y;
137 T s = sin(r), c = cos(r);
138 switch (
unsigned(q) & 3U) {
139 case 0U: sinx = s; cosx = c;
break;
140 case 1U: sinx = c; cosx = -s;
break;
141 case 2U: sinx = -s; cosx = -c;
break;
142 default: sinx = -c; cosx = s;
break;
145 if (x != 0) { sinx += T(0); cosx += T(0); }
154 unsigned p = unsigned(q);
155 r = p & 1U ? cos(r) : sin(r);
157 if (x != 0) r += T(0);
167 unsigned p = unsigned(q + 1);
168 r = p & 1U ? cos(r) : sin(r);
174 static const T overflow = 1 /
sq(numeric_limits<T>::epsilon());
177 return c != 0 ? s / c : (s < 0 ? -overflow : overflow);
186 if (abs(y) > abs(x)) {
swap(x, y); q = 2; }
187 if (x < 0) { x = -x; ++q; }
189 T ang = atan2(y, x) / degree<T>();
197 case 1: ang = (y >= 0 ? 180 : -180) - ang;
break;
198 case 2: ang = 90 - ang;
break;
199 case 3: ang = -90 + ang;
break;
206 {
return atan2d(x, T(1)); }
210 return es > T(0) ? es *
atanh(es * x) : -es * atan(es * x);
215 using std::isfinite;
using std::hypot;
217 T tau1 =
hypot(T(1), tau),
218 sig = sinh(
eatanhe(tau / tau1, es ) );
219 return hypot(T(1), sig) * tau - sig * tau1;
226 static const int numit = 5;
228 static const T tol = sqrt(numeric_limits<T>::epsilon()) / 10;
229 static const T taumax = 2 / sqrt(numeric_limits<T>::epsilon());
230 T e2m = T(1) -
sq(es),
242 tau = abs(taup) > 70 ? taup * exp(
eatanhe(T(1), es)) : taup/e2m,
243 stol = tol * max(T(1), abs(taup));
244 if (!(abs(tau) < taumax))
return tau;
246 T taupa =
taupf(tau, es),
247 dtau = (taup - taupa) * (1 + e2m *
sq(tau)) /
248 ( e2m *
hypot(T(1), tau) *
hypot(T(1), taupa) );
250 if (!(abs(dtau) >= stol))
257 using std::isfinite;
return isfinite(x);
262 return numeric_limits<T>::has_quiet_NaN ?
263 numeric_limits<T>::quiet_NaN() :
264 (numeric_limits<T>::max)();
266 return numeric_limits<T>::has_quiet_NaN ?
267 numeric_limits<T>::quiet_NaN() :
268 numeric_limits<T>::max();
273 using std::isnan;
return isnan(x);
278 return numeric_limits<T>::has_infinity ?
279 numeric_limits<T>::infinity() :
280 (numeric_limits<T>::max)();
282 return numeric_limits<T>::has_infinity ?
283 numeric_limits<T>::infinity() :
284 numeric_limits<T>::max();
290#define GEOGRAPHICLIB_MATH_INSTANTIATE(T) \
291 template T GEOGRAPHICLIB_EXPORT Math::hypot <T>(T, T); \
292 template T GEOGRAPHICLIB_EXPORT Math::expm1 <T>(T); \
293 template T GEOGRAPHICLIB_EXPORT Math::log1p <T>(T); \
294 template T GEOGRAPHICLIB_EXPORT Math::asinh <T>(T); \
295 template T GEOGRAPHICLIB_EXPORT Math::atanh <T>(T); \
296 template T GEOGRAPHICLIB_EXPORT Math::cbrt <T>(T); \
297 template T GEOGRAPHICLIB_EXPORT Math::remainder<T>(T, T); \
298 template T GEOGRAPHICLIB_EXPORT Math::remquo <T>(T, T, int*); \
299 template T GEOGRAPHICLIB_EXPORT Math::round <T>(T); \
300 template long GEOGRAPHICLIB_EXPORT Math::lround <T>(T); \
301 template T GEOGRAPHICLIB_EXPORT Math::copysign <T>(T, T); \
302 template T GEOGRAPHICLIB_EXPORT Math::fma <T>(T, T, T); \
303 template T GEOGRAPHICLIB_EXPORT Math::sum <T>(T, T, T&); \
304 template T GEOGRAPHICLIB_EXPORT Math::AngRound <T>(T); \
305 template void GEOGRAPHICLIB_EXPORT Math::sincosd <T>(T, T&, T&); \
306 template T GEOGRAPHICLIB_EXPORT Math::sind <T>(T); \
307 template T GEOGRAPHICLIB_EXPORT Math::cosd <T>(T); \
308 template T GEOGRAPHICLIB_EXPORT Math::tand <T>(T); \
309 template T GEOGRAPHICLIB_EXPORT Math::atan2d <T>(T, T); \
310 template T GEOGRAPHICLIB_EXPORT Math::atand <T>(T); \
311 template T GEOGRAPHICLIB_EXPORT Math::eatanhe <T>(T, T); \
312 template T GEOGRAPHICLIB_EXPORT Math::taupf <T>(T, T); \
313 template T GEOGRAPHICLIB_EXPORT Math::tauf <T>(T, T); \
314 template bool GEOGRAPHICLIB_EXPORT Math::isfinite <T>(T); \
315 template T GEOGRAPHICLIB_EXPORT Math::NaN <T>(); \
316 template bool GEOGRAPHICLIB_EXPORT Math::isnan <T>(T); \
317 template T GEOGRAPHICLIB_EXPORT Math::infinity <T>();
320 GEOGRAPHICLIB_MATH_INSTANTIATE(
float)
321 GEOGRAPHICLIB_MATH_INSTANTIATE(
double)
322#if GEOGRAPHICLIB_HAVE_LONG_DOUBLE
324 GEOGRAPHICLIB_MATH_INSTANTIATE(
long double)
326#if GEOGRAPHICLIB_PRECISION > 3
331#undef GEOGRAPHICLIB_MATH_INSTANTIATE
#define GEOGRAPHICLIB_EXPORT
Header for GeographicLib::Math class.
#define GEOGRAPHICLIB_VOLATILE
#define GEOGRAPHICLIB_PANIC
#define GEOGRAPHICLIB_PRECISION
static T remquo(T x, T y, int *n)
static void sincosd(T x, T &sinx, T &cosx)
static T atan2d(T y, T x)
static T fma(T x, T y, T z)
static T copysign(T x, T y)
static T sum(T u, T v, T &t)
static T tauf(T taup, T es)
static bool isfinite(T x)
static T taupf(T tau, T es)
static T remainder(T x, T y)
static T eatanhe(T x, T es)
static int set_digits(int ndigits)
static int extra_digits()
Namespace for GeographicLib.
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)