GeographicLib  1.21
Public Types | Static Public Member Functions | Static Public Attributes
GeographicLib::Math Class Reference

Mathematical functions needed by GeographicLib. More...

#include <GeographicLib/Math.hpp>

List of all members.

Public Types

typedef double extended
typedef double real

Static Public Member Functions

template<typename T >
static T pi () throw ()
static real pi () throw ()
template<typename T >
static T degree () throw ()
static real degree () throw ()
template<typename T >
static T sq (T x) throw ()
template<typename T >
static T hypot (T x, T y) throw ()
template<typename T >
static T expm1 (T x) throw ()
template<typename T >
static T log1p (T x) throw ()
template<typename T >
static T asinh (T x) throw ()
template<typename T >
static T atanh (T x) throw ()
template<typename T >
static T cbrt (T x) throw ()
template<typename T >
static bool isfinite (T x) throw ()
template<typename T >
static T NaN () throw ()
static real NaN () throw ()
template<typename T >
static bool isnan (T x) throw ()
template<typename T >
static T infinity () throw ()
static real infinity () throw ()
template<typename T >
static T swab (T x)

Static Public Attributes

static const bool bigendian = WORDS_BIGENDIAN

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
// $Id: 04519bb67e82229a86ee23002ddc27a6b5bb2939 $

#include <iostream>
#include <exception>
#include <GeographicLib/Math.hpp>

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;
  }
  return 0;
}

Member Typedef Documentation

Definition at line 77 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 87 of file Math.hpp.


Member Function Documentation

template<typename T >
static T GeographicLib::Math::pi ( ) throw () [inline, static]
Template Parameters:
Tthe type of the returned value.
Returns:
pi.

Definition at line 105 of file Math.hpp.

static real GeographicLib::Math::pi ( ) throw () [inline, static]

A synonym for pi<real>().

Definition at line 110 of file Math.hpp.

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

Definition at line 116 of file Math.hpp.

static real GeographicLib::Math::degree ( ) throw () [inline, static]

A synonym for degree<real>().

Definition at line 121 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sq ( x) throw () [inline, static]
template<typename T >
static T GeographicLib::Math::hypot ( x,
y 
) throw () [inline, static]
template<typename T >
static T GeographicLib::Math::expm1 ( x) throw () [inline, static]

exp(x) - 1 accurate near x = 0. This is taken from N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd Edition (SIAM, 2002), Sec 1.14.1, p 19.

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

Definition at line 189 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::log1p ( x) throw () [inline, static]

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

This is taken from D. Goldberg, What every computer scientist should know about floating-point arithmetic (1991), Theorem 4. See also, Higham (op. cit.), Answer to Problem 1.5, p 528.

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

Definition at line 224 of file Math.hpp.

Referenced by GeographicLib::LambertConformalConic::Reverse().

template<typename T >
static T GeographicLib::Math::asinh ( x) throw () [inline, static]

The inverse hyperbolic sine function. This is defined in terms of Math::log1p(x) in order to maintain accuracy near x = 0. In addition, the odd parity of the function is enforced.

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

Definition at line 256 of file Math.hpp.

Referenced by GeographicLib::LambertConformalConic::Forward(), and GeographicLib::TransverseMercator::Forward().

template<typename T >
static T GeographicLib::Math::atanh ( x) throw () [inline, static]

The inverse hyperbolic tangent function. This is defined in terms of Math::log1p(x) in order to maintain accuracy near x = 0. In addition, the odd parity of the function is enforced.

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

Definition at line 283 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::cbrt ( x) throw () [inline, static]

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 308 of file Math.hpp.

template<typename T >
static bool GeographicLib::Math::isfinite ( x) throw () [inline, static]
template<typename T >
static T GeographicLib::Math::NaN ( ) throw () [inline, static]

The NaN (not a number)

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

Definition at line 346 of file Math.hpp.

static real GeographicLib::Math::NaN ( ) throw () [inline, static]

A synonym for NaN<real>().

Definition at line 354 of file Math.hpp.

template<typename T >
static bool GeographicLib::Math::isnan ( x) throw () [inline, static]

Test for NaN.

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

Definition at line 363 of file Math.hpp.

Referenced by main().

template<typename T >
static T GeographicLib::Math::infinity ( ) throw () [inline, static]

Infinity

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

Definition at line 377 of file Math.hpp.

static real GeographicLib::Math::infinity ( ) throw () [inline, static]

A synonym for infinity<real>().

Definition at line 385 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::swab ( x) [inline, static]

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 394 of file Math.hpp.


Member Data Documentation

const bool GeographicLib::Math::bigendian = WORDS_BIGENDIAN [static]

true if the machine is big-endian

Definition at line 99 of file Math.hpp.

Referenced by GeographicLib::Utility::readarray(), and GeographicLib::Utility::writearray().


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