Public Types | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
GeographicLib::Math Class Reference

Mathematical functions needed by GeographicLib. More...

#include <Math.hpp>

Public Types

typedef double extended
 
typedef double real
 

Static Public Member Functions

template<typename T >
static T AngDiff (T x, T y, T &e)
 
template<typename T >
static T AngDiff (T x, T y)
 
template<typename T >
static T AngNormalize (T x)
 
template<typename T >
static T AngRound (T x)
 
template<typename T >
static T asinh (T x)
 
template<typename T >
static T atan2d (T y, T x)
 
template<typename T >
static T atand (T x)
 
template<typename T >
static T atanh (T x)
 
template<typename T >
static T cbrt (T x)
 
template<typename T >
static T copysign (T x, T y)
 
template<typename T >
static T cosd (T x)
 
template<typename T >
static T degree ()
 
static real degree ()
 
static int digits ()
 
static int digits10 ()
 
template<typename T >
static T eatanhe (T x, T es)
 
template<typename T >
static T expm1 (T x)
 
static int extra_digits ()
 
template<typename T >
static T fma (T x, T y, T z)
 
template<typename T >
static T hypot (T x, T y)
 
template<typename T >
static T infinity ()
 
static real infinity ()
 
template<typename T >
static bool isfinite (T x)
 
template<typename T >
static bool isnan (T x)
 
template<typename T >
static T LatFix (T x)
 
template<typename T >
static T log1p (T x)
 
template<typename T >
static T NaN ()
 
static real NaN ()
 
template<typename T >
static void norm (T &x, T &y)
 
template<typename T >
static T pi ()
 
static real pi ()
 
template<typename T >
static T polyval (int N, const T p[], T x)
 
static int set_digits (int ndigits)
 
template<typename T >
static void sincosd (T x, T &sinx, T &cosx)
 
template<typename T >
static T sind (T x)
 
template<typename T >
static T sq (T x)
 
template<typename T >
static T sum (T u, T v, T &t)
 
template<typename T >
static T swab (T x)
 
template<typename T >
static T tand (T x)
 
template<typename T >
static T tauf (T taup, T es)
 
template<typename T >
static T taupf (T tau, T es)
 

Static Public Attributes

static const bool bigendian = GEOGRAPHICLIB_WORDS_BIGENDIAN
 

Private Member Functions

void dummy ()
 
 Math ()
 

Detailed Description

Mathematical functions needed by GeographicLib.

Define mathematical functions in order to localize system dependencies and to provide generic versions of the functions. In addition define a real type to be used by GeographicLib.

Example of use:

// Example of using the GeographicLib::Math class
#include <iostream>
#include <exception>
using namespace std;
using namespace GeographicLib;
int main() {
try {
cout << Math::pi() << " " << Math::sq(Math::pi()) << "\n";
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}

Definition at line 102 of file Math.hpp.

Member Typedef Documentation

Definition at line 119 of file Math.hpp.

typedef double GeographicLib::Math::real

The real type for GeographicLib. Nearly all the testing has been done with real = double. However, the algorithms should also work with float and long double (where available). (CAUTION: reasonable accuracy typically cannot be obtained using floats.)

Definition at line 129 of file Math.hpp.

Constructor & Destructor Documentation

GeographicLib::Math::Math ( )
private

Member Function Documentation

template<typename T >
static T GeographicLib::Math::AngDiff ( T  x,
T  y,
T e 
)
inlinestatic

The exact difference of two angles reduced to (−180°, 180°].

Template Parameters
Tthe type of the arguments and returned value.
Parameters
[in]xthe first angle in degrees.
[in]ythe second angle in degrees.
[out]ethe error term in degrees.
Returns
d, the truncated value of yx.

This computes z = yx exactly, reduced to (−180°, 180°]; and then sets z = d + e where d is the nearest representable number to z and e is the truncation error. If d = −180, then e > 0; If d = 180, then e ≤ 0.

Definition at line 486 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::AngDiff ( T  x,
T  y 
)
inlinestatic

Difference of two angles reduced to [−180°, 180°]

Template Parameters
Tthe type of the arguments and returned value.
Parameters
[in]xthe first angle in degrees.
[in]ythe second angle in degrees.
Returns
yx, reduced to the range [−180°, 180°].

The result is equivalent to computing the difference exactly, reducing it to (−180°, 180°] and rounding the result. Note that this prescription allows −180° to be returned (e.g., if x is tiny and negative and y = 180°).

Definition at line 517 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::AngNormalize ( T  x)
inlinestatic

Normalize an angle.

Template Parameters
Tthe type of the argument and returned value.
Parameters
[in]xthe angle in degrees.
Returns
the angle reduced to the range([−180°, 180°].

The range of x is unrestricted.

Definition at line 440 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::AngRound ( T  x)
inlinestatic

Coarsen a value close to zero.

Template Parameters
Tthe type of the argument and returned value.
Parameters
[in]x
Returns
the coarsened value.

The makes the smallest gap in x = 1/16 - nextafter(1/16, 0) = 1/257 for reals = 0.7 pm on the earth if x is an angle in degrees. (This is about 1000 times more resolution than we get with angles around 90°.) We use this to avoid having to deal with near singular cases when x is non-zero but tiny (e.g., 10−200). This converts -0 to +0; however tiny negative numbers get converted to -0.

Definition at line 535 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::asinh ( T  x)
inlinestatic

The inverse hyperbolic sine function.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
asinh(x).

Definition at line 311 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::atan2d ( T  y,
T  x 
)
inlinestatic

Evaluate the atan2 function with the result in degrees

Template Parameters
Tthe type of the arguments and the returned value.
Parameters
[in]y
[in]x
Returns
atan2(y, x) in degrees.

The result is in the range (−180° 180°]. N.B., atan2d(±0, −1) = +180°; atan2d(−ε, −1) = −180°, for ε positive and tiny; atan2d(±0, +1) = ±0°.

Definition at line 691 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::atand ( T  x)
inlinestatic

Evaluate the atan function with the result in degrees

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
atan(x) in degrees.

Definition at line 723 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::atanh ( T  x)
inlinestatic

The inverse hyperbolic tangent function.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
atanh(x).

Definition at line 328 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::cbrt ( T  x)
inlinestatic

The cube root function.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
the real cube root of x.

Definition at line 345 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::copysign ( T  x,
T  y 
)
inlinestatic

Copy the sign.

Template Parameters
Tthe type of the argument.
Parameters
[in]xgives the magitude of the result.
[in]ygives the sign of the result.
Returns
value with the magnitude of x and with the sign of y.

This routine correctly handles the case y = −0, returning &minus|x|.

Definition at line 751 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::cosd ( T  x)
inlinestatic

Evaluate the cosine function with the argument in degrees

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]xin degrees.
Returns
cos(x).

Definition at line 639 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::degree ( )
inlinestatic
Template Parameters
Tthe type of the returned value.
Returns
the number of radians in a degree.

Definition at line 216 of file Math.hpp.

static real GeographicLib::Math::degree ( )
inlinestatic

A synonym for degree<real>().

Definition at line 223 of file Math.hpp.

static int GeographicLib::Math::digits ( )
inlinestatic
Returns
the number of bits of precision in a real number.

Definition at line 145 of file Math.hpp.

static int GeographicLib::Math::digits10 ( )
inlinestatic
Returns
the number of decimal digits of precision in a real number.

Definition at line 175 of file Math.hpp.

void GeographicLib::Math::dummy ( )
inlineprivate

Definition at line 104 of file Math.hpp.

template<typename T >
T GeographicLib::Math::eatanhe ( T  x,
T  es 
)
static

Evaluate e atanh(e x)

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
[in]esthe signed eccentricity = sign(e2) sqrt(|e2|)
Returns
e atanh(e x)

If e2 is negative (e is imaginary), the expression is evaluated in terms of atan.

Definition at line 21 of file Math.cpp.

template<typename T >
static T GeographicLib::Math::expm1 ( T  x)
inlinestatic

exp(x) − 1 accurate near x = 0.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
exp(x) − 1.

Definition at line 265 of file Math.hpp.

static int GeographicLib::Math::extra_digits ( )
inlinestatic

Number of additional decimal digits of precision for real relative to double (0 for float).

Definition at line 187 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::fma ( T  x,
T  y,
T  z 
)
inlinestatic

Fused multiply and add.

Template Parameters
Tthe type of the arguments and the returned value.
Parameters
[in]x
[in]y
[in]z
Returns
xy + z, correctly rounded (on those platforms with support for the fma instruction).

On platforms without the fma instruction, no attempt is made to improve on the result of a rounded multiplication followed by a rounded addition.

Definition at line 369 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::hypot ( T  x,
T  y 
)
inlinestatic

The hypotenuse function avoiding underflow and overflow.

Template Parameters
Tthe type of the arguments and the returned value.
Parameters
[in]x
[in]y
Returns
sqrt(x2 + y2).

Definition at line 243 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::infinity ( )
inlinestatic

Infinity

Template Parameters
Tthe type of the returned value.
Returns
infinity if available, otherwise return the max real.

Definition at line 867 of file Math.hpp.

static real GeographicLib::Math::infinity ( )
inlinestatic

A synonym for infinity<real>().

Definition at line 881 of file Math.hpp.

template<typename T >
static bool GeographicLib::Math::isfinite ( T  x)
inlinestatic

Test for finiteness.

Template Parameters
Tthe type of the argument.
Parameters
[in]x
Returns
true if number is finite, false if NaN or infinite.

Definition at line 806 of file Math.hpp.

template<typename T >
static bool GeographicLib::Math::isnan ( T  x)
inlinestatic

Test for NaN.

Template Parameters
Tthe type of the argument.
Parameters
[in]x
Returns
true if argument is a NaN.

Definition at line 853 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::LatFix ( T  x)
inlinestatic

Normalize a latitude.

Template Parameters
Tthe type of the argument and returned value.
Parameters
[in]xthe angle in degrees.
Returns
x if it is in the range [−90°, 90°], otherwise return NaN.

Definition at line 467 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::log1p ( T  x)
inlinestatic

log(1 + x) accurate near x = 0.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
log(1 + x).

Definition at line 288 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::NaN ( )
inlinestatic

The NaN (not a number)

Template Parameters
Tthe type of the returned value.
Returns
NaN if available, otherwise return the max real of type T.

Definition at line 830 of file Math.hpp.

static real GeographicLib::Math::NaN ( )
inlinestatic

A synonym for NaN<real>().

Definition at line 844 of file Math.hpp.

template<typename T >
static void GeographicLib::Math::norm ( T x,
T y 
)
inlinestatic

Normalize a two-vector.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in,out]xon output set to x/hypot(x, y).
[in,out]yon output set to y/hypot(x, y).

Definition at line 384 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::pi ( )
inlinestatic
Template Parameters
Tthe type of the returned value.
Returns
π.

Definition at line 202 of file Math.hpp.

static real GeographicLib::Math::pi ( )
inlinestatic

A synonym for pi<real>().

Definition at line 210 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::polyval ( int  N,
const T  p[],
T  x 
)
inlinestatic

Evaluate a polynomial.

Template Parameters
Tthe type of the arguments and returned value.
Parameters
[in]Nthe order of the polynomial.
[in]pthe coefficient array (of size N + 1).
[in]xthe variable.
Returns
the value of the polynomial.

Evaluate y = ∑n=0..N pn xNn. Return 0 if N < 0. Return p0, if N = 0 (even if x is infinite or a nan). The evaluation uses Horner's method.

Definition at line 425 of file Math.hpp.

static int GeographicLib::Math::set_digits ( int  ndigits)
inlinestatic

Set the binary precision of a real number.

Parameters
[in]ndigitsthe number of bits of precision.
Returns
the resulting number of bits of precision.

This only has an effect when GEOGRAPHICLIB_PRECISION = 5. See also Utility::set_digits for caveats about when this routine should be called.

Definition at line 163 of file Math.hpp.

template<typename T >
static void GeographicLib::Math::sincosd ( T  x,
T sinx,
T cosx 
)
inlinestatic

Evaluate the sine and cosine function with the argument in degrees

Template Parameters
Tthe type of the arguments.
Parameters
[in]xin degrees.
[out]sinxsin(x).
[out]cosxcos(x).

The results obey exactly the elementary properties of the trigonometric functions, e.g., sin 9° = cos 81° = − sin 123456789°. If x = −0, then sinx = −0; this is the only case where −0 is returned.

Definition at line 558 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sind ( T  x)
inlinestatic

Evaluate the sine function with the argument in degrees

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]xin degrees.
Returns
sin(x).

Definition at line 609 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sq ( T  x)
inlinestatic

Square a number.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
x2.

Definition at line 232 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sum ( T  u,
T  v,
T t 
)
inlinestatic

The error-free sum of two numbers.

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]u
[in]v
[out]tthe exact error given by (u + v) - s.
Returns
s = round(u + v).

See D. E. Knuth, TAOCP, Vol 2, 4.2.2, Theorem B. (Note that t can be the same as one of the first two arguments.)

Definition at line 399 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::swab ( T  x)
inlinestatic

Swap the bytes of a quantity

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]x
Returns
x with its bytes swapped.

Definition at line 890 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::tand ( T  x)
inlinestatic

Evaluate the tangent function with the argument in degrees

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]xin degrees.
Returns
tan(x).

If x = ±90°, then a suitably large (but finite) value is returned.

Definition at line 671 of file Math.hpp.

template<typename T >
T GeographicLib::Math::tauf ( T  taup,
T  es 
)
static

tanφ in terms of tanχ

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]taupτ′ = tanχ
[in]esthe signed eccentricity = sign(e2) sqrt(|e2|)
Returns
τ = tanφ

See Eqs. (19–21) of C. F. F. Karney, Transverse Mercator with an accuracy of a few nanometers, J. Geodesy 85(8), 475–485 (Aug. 2011) (preprint arXiv:1002.1417).

Definition at line 31 of file Math.cpp.

template<typename T >
T GeographicLib::Math::taupf ( T  tau,
T  es 
)
static

tanχ in terms of tanφ

Template Parameters
Tthe type of the argument and the returned value.
Parameters
[in]tauτ = tanφ
[in]esthe signed eccentricity = sign(e2) sqrt(|e2|)
Returns
τ′ = tanχ

See Eqs. (7–9) of C. F. F. Karney, Transverse Mercator with an accuracy of a few nanometers, J. Geodesy 85(8), 475–485 (Aug. 2011) (preprint arXiv:1002.1417).

Definition at line 25 of file Math.cpp.

Member Data Documentation

const bool GeographicLib::Math::bigendian = GEOGRAPHICLIB_WORDS_BIGENDIAN
static

true if the machine is big-endian.

Definition at line 196 of file Math.hpp.


The documentation for this class was generated from the following files:


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:57:59