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;
134 r = remquo(x, T(90), &q);
137 T s = sin(r), c = cos(r);
138 #if defined(_MSC_VER) && _MSC_VER < 1900
147 switch (
unsigned(q) & 3U) {
148 case 0U: sinx = s; cosx = c;
break;
149 case 1U: sinx = c; cosx = -s;
break;
150 case 2U: sinx = -s; cosx = -c;
break;
151 default: sinx = -c; cosx = s;
break;
154 if (x != 0) { sinx += T(0); cosx += T(0); }
161 r = remquo(x, T(90), &q);
163 unsigned p = unsigned(q);
164 r = p & 1U ? cos(r) : sin(r);
166 if (x != 0) r += T(0);
174 r = remquo(x, T(90), &q);
176 unsigned p = unsigned(q + 1);
177 r = p & 1U ? cos(r) : sin(r);
183 static const T overflow = 1 / sq(numeric_limits<T>::epsilon());
186 return c != 0 ? s / c : (s < 0 ? -overflow : overflow);
195 if (abs(y) > abs(x)) {
swap(x, y); q = 2; }
196 if (x < 0) { x = -x; ++q; }
198 T ang = atan2(y, x) / degree<T>();
206 case 1: ang = (y >= 0 ? 180 : -180) - ang;
break;
207 case 2: ang = 90 - ang;
break;
208 case 3: ang = -90 + ang;
break;
214 {
return atan2d(x, T(1)); }
218 return es > T(0) ? es * atanh(es * x) : -es * atan(es * x);
223 using std::isfinite;
using std::hypot;
225 T tau1 = hypot(T(1), tau),
226 sig = sinh( eatanhe(tau / tau1, es ) );
227 return hypot(T(1), sig) * tau - sig * tau1;
234 static const int numit = 5;
236 static const T tol = sqrt(numeric_limits<T>::epsilon()) / 10;
237 static const T taumax = 2 / sqrt(numeric_limits<T>::epsilon());
238 T e2m = T(1) - sq(es),
250 tau = abs(taup) > 70 ? taup * exp(eatanhe(T(1), es)) : taup/e2m,
251 stol = tol * max(T(1), abs(taup));
252 if (!(abs(tau) < taumax))
return tau;
254 T taupa = taupf(tau, es),
255 dtau = (taup - taupa) * (1 + e2m * sq(tau)) /
256 ( e2m * hypot(T(1), tau) * hypot(T(1), taupa) );
258 if (!(abs(dtau) >= stol))
265 using std::isfinite;
return isfinite(x);
269 #if defined(_MSC_VER)
270 return numeric_limits<T>::has_quiet_NaN ?
271 numeric_limits<T>::quiet_NaN() :
272 (numeric_limits<T>::max)();
274 return numeric_limits<T>::has_quiet_NaN ?
275 numeric_limits<T>::quiet_NaN() :
276 numeric_limits<T>::max();
281 using std::isnan;
return isnan(x);
285 #if defined(_MSC_VER)
286 return numeric_limits<T>::has_infinity ?
287 numeric_limits<T>::infinity() :
288 (numeric_limits<T>::max)();
290 return numeric_limits<T>::has_infinity ?
291 numeric_limits<T>::infinity() :
292 numeric_limits<T>::max();
298 #define GEOGRAPHICLIB_MATH_INSTANTIATE(T) \
299 template T GEOGRAPHICLIB_EXPORT Math::hypot <T>(T, T); \
300 template T GEOGRAPHICLIB_EXPORT Math::expm1 <T>(T); \
301 template T GEOGRAPHICLIB_EXPORT Math::log1p <T>(T); \
302 template T GEOGRAPHICLIB_EXPORT Math::asinh <T>(T); \
303 template T GEOGRAPHICLIB_EXPORT Math::atanh <T>(T); \
304 template T GEOGRAPHICLIB_EXPORT Math::cbrt <T>(T); \
305 template T GEOGRAPHICLIB_EXPORT Math::remainder<T>(T, T); \
306 template T GEOGRAPHICLIB_EXPORT Math::remquo <T>(T, T, int*); \
307 template T GEOGRAPHICLIB_EXPORT Math::round <T>(T); \
308 template long GEOGRAPHICLIB_EXPORT Math::lround <T>(T); \
309 template T GEOGRAPHICLIB_EXPORT Math::copysign <T>(T, T); \
310 template T GEOGRAPHICLIB_EXPORT Math::fma <T>(T, T, T); \
311 template T GEOGRAPHICLIB_EXPORT Math::sum <T>(T, T, T&); \
312 template T GEOGRAPHICLIB_EXPORT Math::AngRound <T>(T); \
313 template void GEOGRAPHICLIB_EXPORT Math::sincosd <T>(T, T&, T&); \
314 template T GEOGRAPHICLIB_EXPORT Math::sind <T>(T); \
315 template T GEOGRAPHICLIB_EXPORT Math::cosd <T>(T); \
316 template T GEOGRAPHICLIB_EXPORT Math::tand <T>(T); \
317 template T GEOGRAPHICLIB_EXPORT Math::atan2d <T>(T, T); \
318 template T GEOGRAPHICLIB_EXPORT Math::atand <T>(T); \
319 template T GEOGRAPHICLIB_EXPORT Math::eatanhe <T>(T, T); \
320 template T GEOGRAPHICLIB_EXPORT Math::taupf <T>(T, T); \
321 template T GEOGRAPHICLIB_EXPORT Math::tauf <T>(T, T); \
322 template bool GEOGRAPHICLIB_EXPORT Math::isfinite <T>(T); \
323 template T GEOGRAPHICLIB_EXPORT Math::NaN <T>(); \
324 template bool GEOGRAPHICLIB_EXPORT Math::isnan <T>(T); \
325 template T GEOGRAPHICLIB_EXPORT Math::infinity <T>();
328 GEOGRAPHICLIB_MATH_INSTANTIATE(
float)
329 GEOGRAPHICLIB_MATH_INSTANTIATE(
double)
330 #if GEOGRAPHICLIB_HAVE_LONG_DOUBLE
332 GEOGRAPHICLIB_MATH_INSTANTIATE(
long double)
334 #if GEOGRAPHICLIB_PRECISION > 3
339 #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)