GeographicLib: GeographicLib::Math Class Reference

GeographicLib 2.7

Loading...
Searching...
No Matches
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 = real>
static T | pi ()
template<typename T = real>
static T | degree ()
template<typename T>
static T | sq (T x)
template<typename T>
static void | norm (T &x, T &y)
template<typename T>
static T | sum (T u, T v, T &t)
template<typename T>
static T | polyval (int N, const T p[], T x)
template<typename T>
static T | AngNormalize (T x)
template<typename T>
static T | LatFix (T x)
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 | AngRound (T x)
template<typename T>
static void | sincosd (T x, T &sinx, T &cosx)
template<typename T>
static void | sincosde (T x, T t, T &sinx, T &cosx)
template<typename T>
static T | sind (T x)
template<typename T>
static T | cosd (T x)
template<typename T>
static T | tand (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 | eatanhe (T x, T es)
template<typename T>
static T | taupf (T tau, T es)
template<typename T>
static T | tauf (T taup, T es)
template<typename T>
static T | hypot3 (T x, T y, T z)
template<typename T>
static T | clamp (T x, T a, T b)
template<typename T = real>
static T | NaN ()
template<typename T = real>
static T | infinity ()
template<typename T>
static T | swab (T x)

## Static Public Attributes
static constexpr int | qd = 90
| degrees per quarter turn
static constexpr int | dm = 60
| minutes per degree
static constexpr int | ms = 60
| seconds per minute
static constexpr int | hd = 2 * qd
| degrees per half turn
static constexpr int | td = 2 * hd
| degrees per turn
static constexpr int | ds = dm * ms
| seconds per degree
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;
}
}
main
int main(int argc, const char *const argv[])
Definition Cart3Convert.cpp:52
Math.hpp
Header for GeographicLib::Math class.
GeographicLib::Math::sq
static T sq(T x)
Definition Math.hpp:209
GeographicLib::Math::pi
static T pi()
Definition Math.hpp:187
GeographicLib
Namespace for GeographicLib.
Definition Accumulator.cpp:12
std
Definition NearestNeighbor.hpp:806

Definition at line 82 of file Math.hpp.

## Member Typedef Documentation

## ◆ extended

typedef double GeographicLib::Math::extended

Definition at line 95 of file Math.hpp.

## ◆ real

typedef double GeographicLib::Math::real

Definition at line 115 of file Math.hpp.

## Member Function Documentation

## ◆ digits()

int GeographicLib::Math::digits | ( |  | ) |
| static

Returns
  the number of bits of precision in a real number.

Definition at line 20 of file Math.cpp.

Referenced by GeographicLib::MGRS::Forward(), GeographicLib::GeodesicExact::GeodesicExact(), and set_digits().

## ◆ set_digits()

int GeographicLib::Math::set_digits | ( | int | ndigits | ) |
| 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. See also Utility::set_digits for caveats about when this routine should be called. If GEOGRAPHICLIB_PRECISION > 5, the precision is set to the compile-time value of GEOGRAPHICLIB_PRECISION and ndigits is ignored.

Definition at line 28 of file Math.cpp.

References digits().

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

## ◆ digits10()

int GeographicLib::Math::digits10 | ( |  | ) |
| static

Returns
  the number of decimal digits of precision in a real number.

Definition at line 41 of file Math.cpp.

Referenced by extra_digits().

## ◆ extra_digits()

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

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

Definition at line 49 of file Math.cpp.

References digits10().

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

## ◆ pi()

template<typename T = real>

T GeographicLib::Math::pi | ( |  | ) |
| inlinestatic

Template Parameters

  T | the type of the returned value.

Returns
  π.

Definition at line 187 of file Math.hpp.

References pi().

Referenced by GeographicLib::Ellipsoid::Area(), atan2d(), GeographicLib::EllipticFunction::D(), degree(), GeographicLib::EllipticFunction::deltaD(), GeographicLib::EllipticFunction::deltaE(), GeographicLib::EllipticFunction::deltaEinv(), GeographicLib::EllipticFunction::deltaF(), GeographicLib::EllipticFunction::deltaG(), GeographicLib::EllipticFunction::deltaH(), GeographicLib::EllipticFunction::deltaPi(), GeographicLib::EllipticFunction::E(), GeographicLib::EllipticFunction::Einv(), GeographicLib::Geodesic::EllipsoidArea(), GeographicLib::GeodesicExact::EllipsoidArea(), GeographicLib::EllipticFunction::F(), GeographicLib::TransverseMercator::Forward(), GeographicLib::EllipticFunction::G(), GeographicLib::EllipticFunction::H(), GeographicLib::Trigfun::HalfRange(), GeographicLib::Intersect::Intersect(), GeographicLib::Triaxial::Geodesic3::Inverse(), GeographicLib::NormalGravity::J2ToFlattening(), GeographicLib::EllipticFunction::Pi(), pi(), GeographicLib::Ellipsoid::QuarterMeridian(), GeographicLib::AngleT< T >::radians(), GeographicLib::AngleT< T >::radians(), GeographicLib::AuxLatitude::Rectifying(), GeographicLib::AuxLatitude::RectifyingRadius(), GeographicLib::DST::refine(), GeographicLib::EllipticFunction::Reset(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::EllipticFunction::RF(), GeographicLib::EllipticFunction::RG(), GeographicLib::DST::transform(), GeographicLib::NormalGravity::V0(), and GeographicLib::Ellipsoid::Volume().

## ◆ degree()

template<typename T = real>

T GeographicLib::Math::degree | ( |  | ) |
| inlinestatic

Template Parameters

  T | the type of the returned value.

Returns
  the number of radians in a degree.

Definition at line 197 of file Math.hpp.

References degree(), hd, and pi().

Referenced by GeographicLib::Constants::arcminute(), GeographicLib::Constants::arcsecond(), cosd(), GeographicLib::Constants::degree(), degree(), GeographicLib::GeodesicLineExact::EquatorialArc(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::Rhumb::GenInverse(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::AuxAngle::lamd(), GeographicLib::AuxAngle::lamd(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::TransverseMercatorExact::Reverse(), sincosd(), sincosde(), sind(), GeographicLib::GravityCircle::SphericalAnomaly(), and GeographicLib::GravityModel::SphericalAnomaly().

## ◆ sq()

template<typename T>

T GeographicLib::Math::sq | ( | T | x | ) |
| inlinestatic

Square a number.

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x |

Returns
  x2.

Definition at line 209 of file Math.hpp.

Referenced by GeographicLib::AuxLatitude::Authalic(), GeographicLib::AuxLatitude::AuthalicRadiusSquared(), GeographicLib::Triaxial::Conformal3::beta(), GeographicLib::Triaxial::Cartesian3::cart2rand(), GeographicLib::Triaxial::Cartesian3::carttocart2(), GeographicLib::SphericalEngine::Circle(), GeographicLib::DAuxLatitude::DRectifying(), GeographicLib::Triaxial::Ellipsoid3::Ellipsoid3(), GeographicLib::Triaxial::GeodesicLine3::fline::fics::fics(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::NormalGravity::FlatteningToJ2(), GeographicLib::Ellipsoid::FlatteningToSecondEccentricitySq(), GeographicLib::Ellipsoid::FlatteningToThirdEccentricitySq(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::Triaxial::Conformal3::ForwardSphere(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GravityModel::GravityModel(), GeographicLib::Triaxial::Geodesic3::Inverse(), GeographicLib::NormalGravity::J2ToFlattening(), GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Triaxial::Ellipsoid3::Norm(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::Triaxial::Conformal3::omega(), GeographicLib::NormalGravity::Phi(), GeographicLib::AuxLatitude::Rectifying(), GeographicLib::AuxLatitude::RectifyingRadius(), GeographicLib::EllipticFunction::Reset(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::Triaxial::Conformal3::ReverseSphere(), GeographicLib::EllipticFunction::RG(), GeographicLib::EllipticFunction::RJ(), GeographicLib::AlbersEqualArea::SetScale(), GeographicLib::CircularEngine::SphericalEngine, GeographicLib::NormalGravity::SurfaceGravity(), tand(), tauf(), GeographicLib::Ellipsoid::TransverseCurvatureRadius(), GeographicLib::TransverseMercator::TransverseMercator(), GeographicLib::NormalGravity::V0(), GeographicLib::SphericalEngine::Value(), GeographicLib::Ellipsoid::Volume(), GeographicLib::Triaxial::Conformal3::x(), and GeographicLib::Triaxial::Conformal3::y().

## ◆ norm()

template<typename T>

void GeographicLib::Math::norm | ( | T & | x,
|  | T & | y )
| inlinestatic

Normalize a two-vector.

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in,out] | x | on output set to x/hypot(x, y).
  [in,out] | y | on output set to y/hypot(x, y).

Definition at line 219 of file Math.hpp.

Referenced by GeographicLib::Triaxial::Ellipsoid3::cart2toellip(), and GeographicLib::CassiniSoldner::Reset().

## ◆ sum()

template<typename T>

T GeographicLib::Math::sum | ( | T | u,
|  | T | v,
|  | T & | t )
| 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
  t can be the same as one of the first two arguments.

Definition at line 55 of file Math.cpp.

References GEOGRAPHICLIB_VOLATILE.

Referenced by AngDiff().

## ◆ polyval()

template<typename T>

T GeographicLib::Math::polyval | ( | int | N,
|  | const T | p[],
|  | T | x )
| inlinestatic

Evaluate a polynomial.

Template Parameters

  T | the type of the arguments and returned value.

Parameters

  [in] | N | the order of the polynomial.
  [in] | p | the coefficient array (of size N + 1) with p0 being coefficient of xN.
  [in] | x | the variable.

Returns
  the value of the polynomial.

Evaluate ∑n=0..N pn xN−n. 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 270 of file Math.hpp.

Referenced by GeographicLib::AuxLatitude::AuthalicRadiusSquared(), GeographicLib::AuxLatitude::RectifyingRadius(), and GeographicLib::TransverseMercator::TransverseMercator().

## ◆ AngNormalize()

template<typename T>

T GeographicLib::Math::AngNormalize | ( | T | x | ) |
| static

Normalize an 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. If the result is ±0° or ±180° then the sign is the sign of x.

Definition at line 69 of file Math.cpp.

References hd, and td.

Referenced by GeographicLib::Geoid::CacheArea(), GeographicLib::DMS::DecodeAzimuth(), GeographicLib::EllipticFunction::Ed(), GeographicLib::DMS::Encode(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::GARS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::Georef::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::Geodesic::GenDirectLine(), GeographicLib::GeodesicExact::GenDirectLine(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), main(), GeographicLib::GeoCoords::Reset(), GeographicLib::LocalCartesian::Reset(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::TransverseMercatorExact::Reverse(), and GeographicLib::UTMUPS::StandardZone().

## ◆ LatFix()

template<typename T>

T GeographicLib::Math::LatFix | ( | T | x | ) |
| inlinestatic

Normalize a latitude.

Template Parameters

  T | the type of the argument and returned value.

Parameters

  [in] | x | the angle in degrees.

Returns
  x if it is in the range [−90°, 90°], otherwise return NaN.

Definition at line 303 of file Math.hpp.

References NaN(), and qd.

Referenced by GeographicLib::Ellipsoid::AuthalicLatitude(), GeographicLib::Geoid::CacheArea(), GeographicLib::Ellipsoid::CircleHeight(), GeographicLib::Ellipsoid::CircleRadius(), GeographicLib::Ellipsoid::ConformalLatitude(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::Ellipsoid::GeocentricLatitude(), GeographicLib::Ellipsoid::InverseAuthalicLatitude(), GeographicLib::Ellipsoid::InverseConformalLatitude(), GeographicLib::Ellipsoid::InverseGeocentricLatitude(), GeographicLib::Ellipsoid::InverseParametricLatitude(), GeographicLib::Ellipsoid::InverseRectifyingLatitude(), GeographicLib::Ellipsoid::IsometricLatitude(), GeographicLib::Ellipsoid::MeridianDistance(), GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::Ellipsoid::ParametricLatitude(), GeographicLib::Ellipsoid::RectifyingLatitude(), GeographicLib::LocalCartesian::Reset(), GeographicLib::NormalGravity::SurfaceGravity(), and GeographicLib::Ellipsoid::TransverseCurvatureRadius().

## ◆ AngDiff() [1/2]

template<typename T>

T GeographicLib::Math::AngDiff | ( | T | x,
|  | T | y,
|  | T & | e )
| static

The exact 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.
  [out] | e | the error term in degrees.

Returns
  d, the truncated value of y − x.

This computes z = y − x 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 z = ±0° or ±180°, then the sign of d is given by the sign of y − x. The maximum absolute value of e is 2−26 (for doubles).

Definition at line 80 of file Math.cpp.

References hd, sum(), and td.

Referenced by AngDiff(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::UTMUPS::Forward(), GeographicLib::Rhumb::GenInverse(), and main().

## ◆ AngDiff() [2/2]

template<typename T>

T GeographicLib::Math::AngDiff | ( | T | x,
|  | T | y )
| inlinestatic

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

The result is equivalent to computing the difference exactly, reducing it to [−180°, 180°] and rounding the result.

Definition at line 337 of file Math.hpp.

References AngDiff().

## ◆ AngRound()

template<typename T>

T GeographicLib::Math::AngRound | ( | T | x | ) |
| static

Coarsen a value close to zero.

Template Parameters

  T | the 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 doubles = 0.8 pm on the earth if x is an angle in degrees. (This is about 2000 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 sign of ±0 is preserved.

Definition at line 95 of file Math.cpp.

References GEOGRAPHICLIB_VOLATILE.

Referenced by GeographicLib::Geodesic::GenDirectLine(), GeographicLib::GeodesicExact::GenDirectLine(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), and sincosde().

## ◆ sincosd()

template<typename T>

void GeographicLib::Math::sincosd | ( | T | x,
|  | T & | sinx,
|  | T & | cosx )
| static

Evaluate the sine and cosine function with the argument in degrees

Template Parameters

  T | the type of the arguments.

Parameters

  [in] | x | in degrees.
  [out] | sinx | sin(x).
  [out] | cosx | cos(x).

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

Definition at line 104 of file Math.cpp.

References degree(), and qd.

Referenced by GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::AngleT< T >::AngleT(), GeographicLib::AuxAngle::degrees(), GeographicLib::GravityCircle::Disturbance(), GeographicLib::EllipticFunction::Ed(), GeographicLib::MagneticCircle::FieldGeocentric(), GeographicLib::AlbersEqualArea::Forward(), GeographicLib::AzimuthalEquidistant::Forward(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::Gnomonic::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::Geodesic::GenDirectLine(), GeographicLib::GeodesicExact::GenDirectLine(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::GravityCircle::GeoidHeight(), GeographicLib::GravityCircle::Gravity(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::CircularEngine::operator()(), GeographicLib::CircularEngine::operator()(), GeographicLib::CassiniSoldner::Reset(), GeographicLib::LocalCartesian::Reset(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::GravityCircle::T(), GeographicLib::GravityCircle::T(), tand(), GeographicLib::GravityCircle::V(), and GeographicLib::GravityCircle::W().

## ◆ sincosde()

template<typename T>

void GeographicLib::Math::sincosde | ( | T | x,
|  | T | t,
|  | T & | sinx,
|  | T & | cosx )
| static

Evaluate the sine and cosine with reduced argument plus correction

Template Parameters

  T | the type of the arguments.

Parameters

  [in] | x | reduced angle in degrees.
  [in] | t | correction in degrees.
  [out] | sinx | sin(x + t).
  [out] | cosx | cos(x + t).

This is a variant of Math::sincosd allowing a correction to the angle to be supplied. x must be in [−180°, 180°] and t is assumed to be a small correction. Math::AngRound is applied to the reduced angle to prevent problems with x + t being extremely close but not exactly equal to one of the four cardinal directions.

Definition at line 131 of file Math.cpp.

References AngRound(), degree(), and qd.

## ◆ sind()

template<typename T>

T GeographicLib::Math::sind | ( | T | x | ) |
| static

Evaluate the sine function with the argument in degrees

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x | in degrees.

Returns
  sin(x).

The result is +0 for x = +0 and positive multiples of 180°. The result is −0 for x = -0 and negative multiples of 180°.

Definition at line 172 of file Math.cpp.

References degree(), and qd.

Referenced by GeographicLib::Ellipsoid::MeridionalCurvatureRadius(), GeographicLib::Ellipsoid::NormalCurvatureRadius(), GeographicLib::NormalGravity::SurfaceGravity(), and GeographicLib::Ellipsoid::TransverseCurvatureRadius().

## ◆ cosd()

template<typename T>

T GeographicLib::Math::cosd | ( | T | x | ) |
| static

Evaluate the cosine function with the argument in degrees

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x | in degrees.

Returns
  cos(x).

The result is +0 for x an odd multiple of 90°.

Definition at line 188 of file Math.cpp.

References degree(), and qd.

## ◆ tand()

template<typename T>

T GeographicLib::Math::tand | ( | T | x | ) |
| static

Evaluate the tangent function with the argument in degrees

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x | in degrees.

Returns
  tan(x).

If x is an odd multiple of 90°, then a suitably large (but finite) value is returned.

Definition at line 203 of file Math.cpp.

References clamp(), sincosd(), and sq().

Referenced by GeographicLib::PolarStereographic::Forward(), and GeographicLib::TransverseMercatorExact::Forward().

## ◆ atan2d()

template<typename T>

T GeographicLib::Math::atan2d | ( | T | y,
|  | T | x )
| static

Evaluate the atan2 function with the result in degrees

Template Parameters

  T | the 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°.

Definition at line 212 of file Math.cpp.

References hd, pi(), qd, and std::swap().

Referenced by GeographicLib::AngleT< T >::AngleT(), atand(), GeographicLib::AuxAngle::degrees(), GeographicLib::AngleT< T >::degrees0(), GeographicLib::GeodesicLine::EquatorialArc(), GeographicLib::GeodesicLine::EquatorialAzimuth(), GeographicLib::GeodesicLineExact::EquatorialAzimuth(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::TransverseMercator::Forward(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Rhumb::GenInverse(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::Geodesic::InverseLine(), GeographicLib::GeodesicExact::InverseLine(), GeographicLib::AzimuthalEquidistant::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::PolarStereographic::Reverse(), and GeographicLib::TransverseMercator::Reverse().

## ◆ atand()

template<typename T>

T GeographicLib::Math::atand | ( | T | x | ) |
| static

Evaluate the atan function with the result in degrees

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x |

Returns
  atan(x) in degrees.

Definition at line 234 of file Math.cpp.

References atan2d().

Referenced by GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::PolarStereographic::Reverse(), and GeographicLib::TransverseMercator::Reverse().

## ◆ eatanhe()

template<typename T>

T GeographicLib::Math::eatanhe | ( | T | x,
|  | T | es )
| static

Evaluate e atanh(e x)

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x |
  [in] | es | the 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 237 of file Math.cpp.

Referenced by GeographicLib::LambertConformalConic::Forward(), tauf(), and taupf().

## ◆ taupf()

template<typename T>

T GeographicLib::Math::taupf | ( | T | tau,
|  | T | es )
| static

tanχ in terms of tanφ

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | tau | τ = tanφ
  [in] | es | the 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 241 of file Math.cpp.

References eatanhe().

Referenced by GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::TransverseMercatorExact::Forward(), and tauf().

## ◆ tauf()

template<typename T>

T GeographicLib::Math::tauf | ( | T | taup,
|  | T | es )
| static

tanφ in terms of tanχ

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | taup | τ′ = tanχ
  [in] | es | the 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 251 of file Math.cpp.

References eatanhe(), GEOGRAPHICLIB_PANIC, sq(), and taupf().

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

## ◆ hypot3()

template<typename T>

T GeographicLib::Math::hypot3 | ( | T | x,
|  | T | y,
|  | T | z )
| static

Implement hypot with 3 parameters

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x |
  [in] | y |
  [in] | z |

Returns
  sqrt(x2 + y2 + z2).

Definition at line 285 of file Math.cpp.

Referenced by GeographicLib::Triaxial::Cartesian3::cart2rand(), GeographicLib::Triaxial::Cartesian3::cart2tocart(), GeographicLib::Triaxial::Cartesian3::carttocart2(), and GeographicLib::Triaxial::Ellipsoid3::Norm().

## ◆ clamp()

template<typename T>

T GeographicLib::Math::clamp | ( | T | x,
|  | T | a,
|  | T | b )
| static

Implement work-alike to C++17 clamp function

Template Parameters

  T | the type of the argument and the returned value.

Parameters

  [in] | x |
  [in] | a |
  [in] | b |

Returns
  x if it lies in [a, b]; otherise return the nearest boundary value.

Requires a ≤ b. Unlike std::clamp, x can be a NaN (and this is then returned).

Definition at line 296 of file Math.cpp.

Referenced by tand().

## ◆ NaN()

template<typename T>

T GeographicLib::Math::NaN | ( |  | ) |
| 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 301 of file Math.cpp.

Referenced by GeographicLib::AngleT< T >::AngleT(), GeographicLib::NormalGravity::AngularVelocity(), GeographicLib::GeodesicLine::Azimuth(), GeographicLib::GeodesicLineExact::Azimuth(), GeographicLib::GravityModel::Circle(), GeographicLib::PolygonAreaT< Geodesic >::Clear(), GeographicLib::NormalGravity::DynamicalFormFactor(), GeographicLib::GeodesicLine::EquatorialArc(), GeographicLib::GeodesicLineExact::EquatorialArc(), GeographicLib::GeodesicLine::EquatorialAzimuth(), GeographicLib::GeodesicLineExact::EquatorialAzimuth(), GeographicLib::NormalGravity::EquatorialGravity(), GeographicLib::Geocentric::EquatorialRadius(), GeographicLib::GeodesicLine::EquatorialRadius(), GeographicLib::GeodesicLineExact::EquatorialRadius(), GeographicLib::GravityCircle::EquatorialRadius(), GeographicLib::MagneticCircle::EquatorialRadius(), GeographicLib::NormalGravity::EquatorialRadius(), GeographicLib::Geocentric::Flattening(), GeographicLib::GeodesicLine::Flattening(), GeographicLib::GeodesicLineExact::Flattening(), GeographicLib::GravityCircle::Flattening(), GeographicLib::MagneticCircle::Flattening(), GeographicLib::NormalGravity::Flattening(), GeographicLib::Gnomonic::Forward(), GeographicLib::UTMUPS::Forward(), GeographicLib::GeodesicLine::GenDistance(), GeographicLib::GeodesicLineExact::GenDistance(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::GravityCircle::GeoidHeight(), GeographicLib::NormalGravity::GravityFlattening(), GeographicLib::OSGB::GridReference(), GeographicLib::GravityCircle::Height(), GeographicLib::MagneticCircle::Height(), GeographicLib::Triaxial::Geodesic3::Inverse(), GeographicLib::NormalGravity::J2ToFlattening(), LatFix(), GeographicLib::GeodesicLine::Latitude(), GeographicLib::GeodesicLineExact::Latitude(), GeographicLib::GravityCircle::Latitude(), GeographicLib::MagneticCircle::Latitude(), GeographicLib::GeodesicLine::Longitude(), GeographicLib::GeodesicLineExact::Longitude(), main(), GeographicLib::NormalGravity::MassConstant(), GeographicLib::AngleT< T >::NaN(), GeographicLib::AuxAngle::NaN(), GeographicLib::Utility::nummatch(), GeographicLib::NormalGravity::PolarGravity(), GeographicLib::GARS::Reverse(), GeographicLib::Geohash::Reverse(), GeographicLib::Georef::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::MGRS::Reverse(), GeographicLib::UTMUPS::Reverse(), GeographicLib::GeodesicLine::SetArc(), GeographicLib::GeodesicLineExact::SetArc(), GeographicLib::GravityCircle::SphericalAnomaly(), GeographicLib::NormalGravity::SurfacePotential(), GeographicLib::PolygonAreaT< GeodType >::TestEdge(), GeographicLib::MagneticCircle::Time(), GeographicLib::Triaxial::Conformal3::x(), and GeographicLib::Triaxial::Conformal3::y().

## ◆ infinity()

template<typename T>

T GeographicLib::Math::infinity | ( |  | ) |
| static

Infinity

Template Parameters

  T | the type of the returned value.

Returns
  infinity if available, otherwise return the max real.

Definition at line 308 of file Math.cpp.

Referenced by GeographicLib::Utility::nummatch(), and GeographicLib::EllipticFunction::Reset().

## ◆ swab()

template<typename T>

T GeographicLib::Math::swab | ( | T | x | ) |
| inlinestatic

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

References std::swap().

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

## Member Data Documentation

## ◆ qd

int GeographicLib::Math::qd = 90
| inlinestaticconstexpr

degrees per quarter turn

The constants defining the standard (Babylonian) meanings of degrees, minutes, and seconds, for angles. Read the constants as follows (for example): ms = 60 is the ratio 1 minute / 1 second. The abbreviations are

- t a whole turn (360°)
- h a half turn (180°)
- q a quarter turn (a right angle = 90°)
- d a degree
- m a minute
- s a second

Note that degree() is ratio 1 degree / 1 radian, thus, for example, Math::degree() * Math::qd is the ratio 1 quarter turn / 1 radian = π/2.

Defining all these in one place would mean that it's simple to convert to the centesimal system for measuring angles. The DMS class assumes that Math::dm and Math::ms are less than or equal to 100 (so that two digits suffice for the integer parts of the minutes and degrees components of an angle). Switching to the centesimal convention will break most of the tests. Also the normal definition of degree is baked into some classes, e.g., UTMUPS, MGRS, Georef, Geohash, etc.

Definition at line 142 of file Math.hpp.

Referenced by GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::AlbersEqualArea::AlbersEqualArea(), atan2d(), GeographicLib::Geoid::CacheAll(), GeographicLib::Geoid::CacheNorth(), GeographicLib::Geoid::CacheSouth(), cosd(), GeographicLib::DMS::DecodeLatLon(), GeographicLib::CassiniSoldner::Forward(), GeographicLib::GARS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::Georef::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::UTMUPS::Forward(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::LambertConformalConic::LambertConformalConic(), LatFix(), main(), GeographicLib::CassiniSoldner::Reverse(), GeographicLib::Geohash::Reverse(), GeographicLib::MGRS::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::TransverseMercatorExact::Reverse(), GeographicLib::AlbersEqualArea::SetScale(), GeographicLib::LambertConformalConic::SetScale(), GeographicLib::PolarStereographic::SetScale(), sincosd(), sincosde(), and sind().

## ◆ dm

int GeographicLib::Math::dm = 60
| inlinestaticconstexpr

minutes per degree

Definition at line 143 of file Math.hpp.

Referenced by GeographicLib::Constants::arcminute(), GeographicLib::DMS::Decode(), GeographicLib::DMS::Encode(), GeographicLib::DMS::Encode(), and GeographicLib::DMS::Encode().

## ◆ ms

int GeographicLib::Math::ms = 60
| inlinestaticconstexpr

seconds per minute

Definition at line 144 of file Math.hpp.

Referenced by GeographicLib::DMS::Decode(), GeographicLib::DMS::Encode(), and GeographicLib::DMS::Encode().

## ◆ hd

int GeographicLib::Math::hd = 2 * qd
| inlinestaticconstexpr

degrees per half turn

Definition at line 145 of file Math.hpp.

Referenced by AngDiff(), AngNormalize(), atan2d(), degree(), GeographicLib::GARS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::RhumbLine::GenPosition(), GeographicLib::Geoid::Geoid(), GeographicLib::Geohash::LatitudeResolution(), main(), GeographicLib::Geohash::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::TransverseMercatorExact::Reverse(), and GeographicLib::UTMUPS::StandardZone().

## ◆ td

int GeographicLib::Math::td = 2 * hd
| inlinestaticconstexpr

degrees per turn

Definition at line 146 of file Math.hpp.

Referenced by AngDiff(), GeographicLib::AngleT< T >::AngleT(), AngNormalize(), GeographicLib::Geoid::CacheAll(), GeographicLib::Geoid::CacheArea(), GeographicLib::AuxLatitude::Convert(), GeographicLib::EllipticFunction::Ed(), GeographicLib::Rhumb::EllipsoidArea(), GeographicLib::DMS::Encode(), GeographicLib::Geoid::Geoid(), GeographicLib::Geohash::LongitudeResolution(), GeographicLib::AngleT< T >::operator T(), and GeographicLib::GARS::Reverse().

## ◆ ds

int GeographicLib::Math::ds = dm * ms
| inlinestaticconstexpr

seconds per degree

Definition at line 147 of file Math.hpp.

Referenced by GeographicLib::Constants::arcsecond(), GeographicLib::DMS::Encode(), and main().

## ◆ bigendian

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

true if the machine is big-endian.

Definition at line 181 of file Math.hpp.

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

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

- Math.hpp
- Math.cpp