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

static int digits ()
static int set_digits (int ndigits)
static int digits10 ()
static int extra_digits ()
template<typename T >
static T pi ()
static real pi ()
template<typename T >
static T degree ()
static real degree ()
template<typename T >
static T sq (T x)
template<typename T >
static T hypot (T x, T y)
template<typename T >
static T expm1 (T x)
template<typename T >
static T log1p (T x)
template<typename T >
static T asinh (T x)
template<typename T >
static T atanh (T x)
template<typename T >
static T cbrt (T x)
template<typename T >
static T sum (T u, T v, T &t)
template<typename T >
static T AngNormalize (T x)
template<typename T >
static T AngNormalize2 (T x)
template<typename T >
static T AngDiff (T x, T y)
template<typename T >
static bool isfinite (T x)
template<typename T >
static T NaN ()
static real NaN ()
template<typename T >
static bool isnan (T x)
template<typename T >
static T infinity ()
static real infinity ()
template<typename T >
static T swab (T x)

Static Public Attributes

static const int extradigits
static const bool bigendian = GEOGRAPHICLIB_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

#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;
}

Definition at line 101 of file Math.hpp.


Member Typedef Documentation

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


Member Function Documentation

static int GeographicLib::Math::digits (  )  [inline, static]
Returns:
the number of bits of precision in a real number.

Definition at line 144 of file Math.hpp.

static int GeographicLib::Math::set_digits ( int  ndigits  )  [inline, static]

Set the binary precision of a real number.

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

This only has an effect when GEOGRAPHICLIB_PRECISION == 5.

Definition at line 160 of file Math.hpp.

static int GeographicLib::Math::digits10 (  )  [inline, static]
Returns:
the number of decimal digits of precision in a real number.

Definition at line 172 of file Math.hpp.

static int GeographicLib::Math::extra_digits (  )  [inline, static]

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

Definition at line 184 of file Math.hpp.

Referenced by GeographicLib::GeoCoords::DMSRepresentation(), GeographicLib::DMS::Encode(), and GeographicLib::GeoCoords::GeoRepresentation().

template<typename T >
static T GeographicLib::Math::pi (  )  [inline, static]
static real GeographicLib::Math::pi (  )  [inline, static]

A synonym for pi<real>().

Definition at line 221 of file Math.hpp.

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

Definition at line 227 of file Math.hpp.

Referenced by GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::Constants::arcminute(), GeographicLib::Constants::arcsecond(), GeographicLib::Constants::degree(), GeographicLib::EllipticFunction::Ed(), GeographicLib::GeodesicLineExact::EquatorialArc(), GeographicLib::GeodesicLine::EquatorialArc(), GeographicLib::GeodesicLineExact::EquatorialAzimuth(), GeographicLib::GeodesicLine::EquatorialAzimuth(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::Gnomonic::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::AzimuthalEquidistant::Forward(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::Rhumb::Inverse(), GeographicLib::Ellipsoid::InverseIsometricLatitude(), GeographicLib::Ellipsoid::InverseRectifyingLatitude(), GeographicLib::Ellipsoid::IsometricLatitude(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::RhumbLine::Position(), GeographicLib::LocalCartesian::Reset(), GeographicLib::CassiniSoldner::Reset(), GeographicLib::TransverseMercatorExact::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::AzimuthalEquidistant::Reverse(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::GravityModel::SphericalAnomaly(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::NormalGravity::SurfaceGravity(), and GeographicLib::Ellipsoid::TransverseCurvatureRadius().

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

A synonym for degree<real>().

Definition at line 234 of file Math.hpp.

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

Square a number.

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

Definition at line 243 of file Math.hpp.

Referenced by GeographicLib::Ellipsoid::Area(), GeographicLib::SphericalEngine::Circle(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::NormalGravity::FlatteningToJ2(), GeographicLib::Ellipsoid::FlatteningToSecondEccentricitySq(), GeographicLib::Ellipsoid::FlatteningToThirdEccentricitySq(), GeographicLib::TransverseMercator::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::GravityModel::GravityModel(), GeographicLib::NormalGravity::J2ToFlattening(), GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::NormalGravity::Phi(), GeographicLib::EllipticFunction::Reset(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::EllipticFunction::RG(), GeographicLib::EllipticFunction::RJ(), GeographicLib::AlbersEqualArea::SetScale(), GeographicLib::NormalGravity::SurfaceGravity(), GeographicLib::Ellipsoid::TransverseCurvatureRadius(), GeographicLib::TransverseMercator::TransverseMercator(), GeographicLib::NormalGravity::V0(), GeographicLib::SphericalEngine::Value(), and GeographicLib::Ellipsoid::Volume().

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

exp(x) 1 accurate near x = 0.

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

Definition at line 276 of file Math.hpp.

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

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

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

Definition at line 299 of file Math.hpp.

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

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

The inverse hyperbolic sine function.

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

Definition at line 322 of file Math.hpp.

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

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

The inverse hyperbolic tangent function.

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

Definition at line 339 of file Math.hpp.

Referenced by GeographicLib::Ellipsoid::Area(), and GeographicLib::EllipticFunction::RC().

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

The cube root function.

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

Definition at line 356 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sum ( u,
v,
T &  t 
) [inline, static]

The error-free sum of two numbers.

Template Parameters:
T the type of the argument and the returned value.
Parameters:
[in] u 
[in] v 
[out] t the 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 378 of file Math.hpp.

References GEOGRAPHICLIB_VOLATILE.

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

Normalize an arbitrary angle.

Template Parameters:
T the type of the argument and returned value.
Parameters:
[in] x the angle in degrees.
Returns:
the angle reduced to the range [180, 180).

The range of x is unrestricted.

Definition at line 411 of file Math.hpp.

Referenced by GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), and GeographicLib::RhumbLine::Position().

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

Difference of two angles reduced to [180, 180]

Template Parameters:
T the type of the arguments and returned value.
Parameters:
[in] x the first angle in degrees.
[in] y the second angle in degrees.
Returns:
y x, reduced to the range [180, 180].

x and y must both lie in [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 429 of file Math.hpp.

Referenced by GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), and GeographicLib::Rhumb::Inverse().

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

The NaN (not a number)

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

Definition at line 460 of file Math.hpp.

Referenced by GeographicLib::NormalGravity::AngularVelocity(), GeographicLib::GeodesicLineExact::Azimuth(), GeographicLib::GeodesicLine::Azimuth(), GeographicLib::GravityModel::Circle(), GeographicLib::PolygonAreaT< GeodType >::Clear(), GeographicLib::NormalGravity::DynamicalFormFactor(), GeographicLib::GeodesicLineExact::EquatorialArc(), GeographicLib::GeodesicLine::EquatorialArc(), GeographicLib::GeodesicLineExact::EquatorialAzimuth(), GeographicLib::GeodesicLine::EquatorialAzimuth(), GeographicLib::NormalGravity::EquatorialGravity(), GeographicLib::NormalGravity::Flattening(), GeographicLib::MagneticCircle::Flattening(), GeographicLib::GravityCircle::Flattening(), GeographicLib::GeodesicLineExact::Flattening(), GeographicLib::GeodesicLine::Flattening(), GeographicLib::Geocentric::Flattening(), GeographicLib::UTMUPS::Forward(), GeographicLib::Gnomonic::Forward(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GravityCircle::GeoidHeight(), GeographicLib::NormalGravity::GravityFlattening(), GeographicLib::MagneticCircle::Height(), GeographicLib::GravityCircle::Height(), GeographicLib::MagneticCircle::Latitude(), GeographicLib::GravityCircle::Latitude(), GeographicLib::GeodesicLineExact::Latitude(), GeographicLib::GeodesicLine::Latitude(), GeographicLib::GeodesicLineExact::Longitude(), GeographicLib::GeodesicLine::Longitude(), GeographicLib::NormalGravity::MajorRadius(), GeographicLib::MagneticCircle::MajorRadius(), GeographicLib::GravityCircle::MajorRadius(), GeographicLib::GeodesicLineExact::MajorRadius(), GeographicLib::GeodesicLine::MajorRadius(), GeographicLib::Geocentric::MajorRadius(), GeographicLib::NormalGravity::MassConstant(), GeographicLib::NormalGravity::PolarGravity(), GeographicLib::RhumbLine::Position(), GeographicLib::UTMUPS::Reverse(), GeographicLib::MGRS::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::Geohash::Reverse(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::NormalGravity::SurfacePotential(), GeographicLib::PolygonAreaT< GeodType >::TestEdge(), and GeographicLib::MagneticCircle::Time().

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

A synonym for NaN<real>().

Definition at line 468 of file Math.hpp.

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

Test for NaN.

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

Definition at line 477 of file Math.hpp.

Referenced by GeographicLib::MGRS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::GeoCoords::GeoRepresentation(), GeographicLib::UTMUPS::Reverse(), and GeographicLib::UTMUPS::StandardZone().

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

Infinity

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

Definition at line 491 of file Math.hpp.

Referenced by GeographicLib::EllipticFunction::Reset().

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

A synonym for infinity<real>().

Definition at line 499 of file Math.hpp.

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

Swap the bytes of a quantity

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

Definition at line 508 of file Math.hpp.


Member Data Documentation

Initial value:
      std::numeric_limits<real>::digits10 >
      std::numeric_limits<double>::digits10 ?
      std::numeric_limits<real>::digits10 -
      std::numeric_limits<double>::digits10 : 0

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

DEPRECATED: use extra_digits() instead

Definition at line 197 of file Math.hpp.

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

true if the machine is big-endian.

Definition at line 207 of file Math.hpp.

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 6 Oct 2014 for GeographicLib by  doxygen 1.6.1