GeographicLib  1.40
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
GeographicLib::Math Class Reference

Mathematical functions needed by GeographicLib. More...

#include <GeographicLib/Math.hpp>

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>
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 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.

Member Function Documentation

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::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.

Definition at line 161 of file Math.hpp.

Referenced by GeographicLib::Utility::set_digits().

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

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

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

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

A synonym for pi<real>().

Definition at line 222 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 228 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::AzimuthalEquidistant::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::Gnomonic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::Rhumb::GenInverse(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::Ellipsoid::InverseIsometricLatitude(), GeographicLib::Ellipsoid::InverseRectifyingLatitude(), GeographicLib::Ellipsoid::IsometricLatitude(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::LocalCartesian::Reset(), GeographicLib::CassiniSoldner::Reset(), GeographicLib::AzimuthalEquidistant::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::TransverseMercatorExact::Reverse(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::GravityModel::SphericalAnomaly(), GeographicLib::NormalGravity::SurfaceGravity(), and GeographicLib::Ellipsoid::TransverseCurvatureRadius().

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

A synonym for degree<real>().

Definition at line 235 of file Math.hpp.

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

Square a number.

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

Definition at line 244 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::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::LambertConformalConic::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::PolarStereographic::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::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 
)
inlinestatic
template<typename T >
static T GeographicLib::Math::expm1 ( 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 277 of file Math.hpp.

References GEOGRAPHICLIB_VOLATILE.

template<typename T >
static T GeographicLib::Math::log1p ( 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 300 of file Math.hpp.

References GEOGRAPHICLIB_VOLATILE.

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

template<typename T >
static T GeographicLib::Math::asinh ( 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 323 of file Math.hpp.

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

template<typename T >
static T GeographicLib::Math::atanh ( 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 340 of file Math.hpp.

Referenced by GeographicLib::Ellipsoid::Area().

template<typename T >
static T GeographicLib::Math::cbrt ( 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 357 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::sum ( u,
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 379 of file Math.hpp.

References GEOGRAPHICLIB_VOLATILE.

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

Normalize an arbitrary 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 412 of file Math.hpp.

Referenced by GeographicLib::PolygonAreaT< GeodType >::AddEdge(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::RhumbLine::GenPosition(), and GeographicLib::PolygonAreaT< GeodType >::TestEdge().

template<typename T >
static T GeographicLib::Math::AngDiff ( x,
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°].

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

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

template<typename T >
static bool GeographicLib::Math::isfinite ( x)
inlinestatic
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 461 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::MagneticCircle::Flattening(), GeographicLib::Geocentric::Flattening(), GeographicLib::GravityCircle::Flattening(), GeographicLib::NormalGravity::Flattening(), GeographicLib::GeodesicLineExact::Flattening(), GeographicLib::GeodesicLine::Flattening(), GeographicLib::Gnomonic::Forward(), GeographicLib::UTMUPS::Forward(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::GravityCircle::GeoidHeight(), GeographicLib::NormalGravity::GravityFlattening(), GeographicLib::OSGB::GridReference(), GeographicLib::MagneticCircle::Height(), GeographicLib::GravityCircle::Height(), GeographicLib::MagneticCircle::Latitude(), GeographicLib::GravityCircle::Latitude(), GeographicLib::GeodesicLineExact::Latitude(), GeographicLib::GeodesicLine::Latitude(), GeographicLib::GeodesicLineExact::Longitude(), GeographicLib::GeodesicLine::Longitude(), main(), GeographicLib::MagneticCircle::MajorRadius(), GeographicLib::NormalGravity::MajorRadius(), GeographicLib::Geocentric::MajorRadius(), GeographicLib::GravityCircle::MajorRadius(), GeographicLib::GeodesicLineExact::MajorRadius(), GeographicLib::GeodesicLine::MajorRadius(), GeographicLib::NormalGravity::MassConstant(), GeographicLib::NormalGravity::PolarGravity(), GeographicLib::Geohash::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::UTMUPS::Reverse(), GeographicLib::MGRS::Reverse(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::NormalGravity::SurfacePotential(), GeographicLib::PolygonAreaT< GeodType >::TestEdge(), and GeographicLib::MagneticCircle::Time().

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

A synonym for NaN<real>().

Definition at line 469 of file Math.hpp.

template<typename T >
static bool GeographicLib::Math::isnan ( 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 478 of file Math.hpp.

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

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

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

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

A synonym for infinity<real>().

Definition at line 500 of file Math.hpp.

template<typename T >
static T GeographicLib::Math::swab ( 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 509 of file Math.hpp.

Member Data Documentation

const int GeographicLib::Math::extradigits
static
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 198 of file Math.hpp.

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

true if the machine is big-endian.

Definition at line 208 of file Math.hpp.

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


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