14# pragma warning (disable: 4127 5055)
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;
65 t = s != 0 ? T(0) - (up + vpp) : s;
72 T y = remainder(x, T(
td));
73#if GEOGRAPHICLIB_PRECISION == 4
77 if (y == 0) y = copysign(y, x);
79 return fabs(y) == T(
hd) ? copysign(T(
hd), x) : y;
85 T d =
sum(remainder(-x, T(
td)), remainder( y, T(
td)), e);
88 d =
sum(remainder(d, T(
td)), e, e);
90 if (d == 0 || fabs(d) ==
hd)
93 d = copysign(d, e == 0 ? y - x : -e);
98 static const T z = T(1)/T(16);
102 y = w > 0 ? z - w : y;
103 return copysign(y, x);
110 r = remquo(x, T(
qd), &q);
113 T s = sin(r), c = cos(r);
114 switch (
unsigned(q) & 3U) {
115 case 0U: sinx = s; cosx = c;
break;
116 case 1U: sinx = c; cosx = -s;
break;
117 case 2U: sinx = -s; cosx = -c;
break;
118 default: sinx = -c; cosx = s;
break;
123 if (sinx == 0) sinx = copysign(sinx, x);
135 T s = sin(r), c = cos(r);
136 switch (
unsigned(q) & 3U) {
137 case 0U: sinx = s; cosx = c;
break;
138 case 1U: sinx = c; cosx = -s;
break;
139 case 2U: sinx = -s; cosx = -c;
break;
140 default: sinx = -c; cosx = s;
break;
145 if (sinx == 0) sinx = copysign(sinx, x);
151 r = remquo(x, T(
qd), &q);
153 unsigned p = unsigned(q);
154 r = p & 1U ? cos(r) : sin(r);
156 if (r == 0) r = copysign(r, x);
163 r = remquo(x, T(
qd), &q);
165 unsigned p = unsigned(q + 1);
166 r = p & 1U ? cos(r) : sin(r);
173 static const T overflow = 1 /
sq(numeric_limits<T>::epsilon());
180 return min(max(r, -overflow), overflow);
189 if (fabs(y) > fabs(x)) {
swap(x, y); q = 2; }
190 if (signbit(x)) { x = -x; ++q; }
192 T ang = atan2(y, x) / degree<T>();
194 case 1: ang = copysign(T(
hd), y) - ang;
break;
195 case 2: ang =
qd - ang;
break;
196 case 3: ang = -
qd + ang;
break;
203 {
return atan2d(x, T(1)); }
206 return es > 0 ? es * atanh(es * x) : -es * atan(es * x);
212 T tau1 = hypot(T(1), tau),
213 sig = sinh(
eatanhe(tau / tau1, es ) );
214 return hypot(T(1), sig) * tau - sig * tau1;
220 static const int numit = 5;
222 static const T tol = sqrt(numeric_limits<T>::epsilon()) / 10;
223 static const T taumax = 2 / sqrt(numeric_limits<T>::epsilon());
236 tau = fabs(taup) > 70 ? taup * exp(
eatanhe(T(1), es)) : taup/e2m,
237 stol = tol * fmax(T(1), fabs(taup));
238 if (!(fabs(tau) < taumax))
return tau;
240 T taupa =
taupf(tau, es),
241 dtau = (taup - taupa) * (1 + e2m *
sq(tau)) /
242 ( e2m * hypot(T(1), tau) * hypot(T(1), taupa) );
244 if (!(fabs(dtau) >= stol))
252 return numeric_limits<T>::has_quiet_NaN ?
253 numeric_limits<T>::quiet_NaN() :
254 (numeric_limits<T>::max)();
256 return numeric_limits<T>::has_quiet_NaN ?
257 numeric_limits<T>::quiet_NaN() :
258 numeric_limits<T>::max();
264 return numeric_limits<T>::has_infinity ?
265 numeric_limits<T>::infinity() :
266 (numeric_limits<T>::max)();
268 return numeric_limits<T>::has_infinity ?
269 numeric_limits<T>::infinity() :
270 numeric_limits<T>::max();
276#define GEOGRAPHICLIB_MATH_INSTANTIATE(T) \
277 template T GEOGRAPHICLIB_EXPORT Math::sum <T>(T, T, T&); \
278 template T GEOGRAPHICLIB_EXPORT Math::AngNormalize <T>(T); \
279 template T GEOGRAPHICLIB_EXPORT Math::AngDiff <T>(T, T, T&); \
280 template T GEOGRAPHICLIB_EXPORT Math::AngRound <T>(T); \
281 template void GEOGRAPHICLIB_EXPORT Math::sincosd <T>(T, T&, T&); \
282 template void GEOGRAPHICLIB_EXPORT Math::sincosde <T>(T, T, T&, T&); \
283 template T GEOGRAPHICLIB_EXPORT Math::sind <T>(T); \
284 template T GEOGRAPHICLIB_EXPORT Math::cosd <T>(T); \
285 template T GEOGRAPHICLIB_EXPORT Math::tand <T>(T); \
286 template T GEOGRAPHICLIB_EXPORT Math::atan2d <T>(T, T); \
287 template T GEOGRAPHICLIB_EXPORT Math::atand <T>(T); \
288 template T GEOGRAPHICLIB_EXPORT Math::eatanhe <T>(T, T); \
289 template T GEOGRAPHICLIB_EXPORT Math::taupf <T>(T, T); \
290 template T GEOGRAPHICLIB_EXPORT Math::tauf <T>(T, T); \
291 template T GEOGRAPHICLIB_EXPORT Math::NaN <T>(); \
292 template T GEOGRAPHICLIB_EXPORT Math::infinity <T>();
295 GEOGRAPHICLIB_MATH_INSTANTIATE(
float)
296 GEOGRAPHICLIB_MATH_INSTANTIATE(
double)
297#if GEOGRAPHICLIB_HAVE_LONG_DOUBLE
299 GEOGRAPHICLIB_MATH_INSTANTIATE(
long double)
301#if GEOGRAPHICLIB_PRECISION > 3
306#undef GEOGRAPHICLIB_MATH_INSTANTIATE
#define GEOGRAPHICLIB_EXPORT
Header for GeographicLib::Math class.
#define GEOGRAPHICLIB_VOLATILE
#define GEOGRAPHICLIB_PANIC
#define GEOGRAPHICLIB_PRECISION
static void sincosd(T x, T &sinx, T &cosx)
static T atan2d(T y, T x)
static T sum(T u, T v, T &t)
static T tauf(T taup, T es)
static T AngNormalize(T x)
static void sincosde(T x, T t, T &sinx, T &cosx)
static T taupf(T tau, T es)
static T AngDiff(T x, T y, T &e)
static T eatanhe(T x, T es)
static int set_digits(int ndigits)
@ hd
degrees per half turn
@ qd
degrees per quarter turn
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)