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 |
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.
typedef double GeographicLib::Math::extended |
typedef double GeographicLib::Math::real |
static int GeographicLib::Math::digits | ( | ) | [inline, static] |
static int GeographicLib::Math::set_digits | ( | int | ndigits | ) | [inline, static] |
static int GeographicLib::Math::digits10 | ( | ) | [inline, static] |
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().
static T GeographicLib::Math::pi | ( | ) | [inline, static] |
T | the type of the returned value. |
Definition at line 213 of file Math.hpp.
Referenced by GeographicLib::Ellipsoid::Area(), GeographicLib::EllipticFunction::D(), 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::GeodesicExact::EllipsoidArea(), GeographicLib::Geodesic::EllipsoidArea(), GeographicLib::EllipticFunction::F(), GeographicLib::TransverseMercator::Forward(), GeographicLib::EllipticFunction::G(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::EllipticFunction::H(), GeographicLib::EllipticFunction::Pi(), GeographicLib::EllipticFunction::Reset(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::EllipticFunction::RF(), GeographicLib::EllipticFunction::RG(), and GeographicLib::Ellipsoid::Volume().
static real GeographicLib::Math::pi | ( | ) | [inline, static] |
A synonym for pi<real>().
static T GeographicLib::Math::degree | ( | ) | [inline, static] |
T | the type of the returned value. |
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>().
static T GeographicLib::Math::sq | ( | T | x | ) | [inline, static] |
Square a number.
T | the type of the argument and the returned value. |
[in] | x |
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().
static T GeographicLib::Math::hypot | ( | T | x, | |
T | y | |||
) | [inline, static] |
The hypotenuse function avoiding underflow and overflow.
T | the type of the arguments and the returned value. |
[in] | x | |
[in] | y |
Definition at line 254 of file Math.hpp.
Referenced by GeographicLib::SphericalEngine::Circle(), GeographicLib::GravityModel::Circle(), GeographicLib::Ellipsoid::CircleHeight(), GeographicLib::Ellipsoid::CircleRadius(), GeographicLib::MagneticModel::FieldComponents(), GeographicLib::TransverseMercator::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::GeodesicExact::GenInverse(), GeographicLib::Geodesic::GenInverse(), GeographicLib::GeodesicLineExact::GenPosition(), GeographicLib::GeodesicLine::GenPosition(), GeographicLib::GeodesicLine::GeodesicLine(), GeographicLib::GeodesicLineExact::GeodesicLineExact(), GeographicLib::GravityModel::GeoidHeight(), GeographicLib::Rhumb::Inverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::PolarStereographic::Reverse(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::Gnomonic::Reverse(), GeographicLib::AzimuthalEquidistant::Reverse(), GeographicLib::AlbersEqualArea::Reverse(), GeographicLib::GravityModel::SphericalAnomaly(), GeographicLib::NormalGravity::V0(), and GeographicLib::SphericalEngine::Value().
static T GeographicLib::Math::expm1 | ( | T | x | ) | [inline, static] |
static T GeographicLib::Math::log1p | ( | T | x | ) | [inline, static] |
log(1 + x) accurate near x = 0.
T | the type of the argument and the returned value. |
[in] | x |
Definition at line 299 of file Math.hpp.
Referenced by GeographicLib::LambertConformalConic::Reverse().
static T GeographicLib::Math::asinh | ( | T | x | ) | [inline, static] |
The inverse hyperbolic sine function.
T | the type of the argument and the returned value. |
[in] | x |
Definition at line 322 of file Math.hpp.
Referenced by GeographicLib::TransverseMercator::Forward(), GeographicLib::LambertConformalConic::Forward(), and GeographicLib::Ellipsoid::IsometricLatitude().
static T GeographicLib::Math::atanh | ( | T | x | ) | [inline, static] |
The inverse hyperbolic tangent function.
T | the type of the argument and the returned value. |
[in] | x |
Definition at line 339 of file Math.hpp.
Referenced by GeographicLib::Ellipsoid::Area(), and GeographicLib::EllipticFunction::RC().
static T GeographicLib::Math::cbrt | ( | T | x | ) | [inline, static] |
static T GeographicLib::Math::sum | ( | T | u, | |
T | v, | |||
T & | t | |||
) | [inline, static] |
The error-free sum of two numbers.
T | the type of the argument and the returned value. |
[in] | u | |
[in] | v | |
[out] | t | the exact error given by (u + v) - s. |
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.
static T GeographicLib::Math::AngNormalize | ( | T | x | ) | [inline, static] |
Normalize an angle (restricted input range).
T | the type of the argument and returned value. |
[in] | x | the angle in degrees. |
x must lie in [540, 540).
Definition at line 399 of file Math.hpp.
Referenced by GeographicLib::PolygonAreaT< GeodType >::AddPoint(), GeographicLib::Geoid::CacheArea(), GeographicLib::DMS::DecodeAzimuth(), GeographicLib::DMS::DecodeLatLon(), GeographicLib::TransverseMercatorExact::Forward(), GeographicLib::TransverseMercator::Forward(), GeographicLib::PolarStereographic::Forward(), GeographicLib::LambertConformalConic::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::CassiniSoldner::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::RhumbLine::Position(), GeographicLib::LocalCartesian::Reset(), GeographicLib::TransverseMercatorExact::Reverse(), GeographicLib::TransverseMercator::Reverse(), GeographicLib::LambertConformalConic::Reverse(), and GeographicLib::AlbersEqualArea::Reverse().
static T GeographicLib::Math::AngNormalize2 | ( | T | x | ) | [inline, static] |
Normalize an arbitrary angle.
T | the type of the argument and returned value. |
[in] | x | the angle in degrees. |
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().
static T GeographicLib::Math::AngDiff | ( | T | x, | |
T | y | |||
) | [inline, static] |
Difference of two angles reduced to [180, 180]
T | the type of the arguments and returned value. |
[in] | x | the first angle in degrees. |
[in] | y | the second angle in degrees. |
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().
static bool GeographicLib::Math::isfinite | ( | T | x | ) | [inline, static] |
Test for finiteness.
T | the type of the argument. |
[in] | x |
Definition at line 445 of file Math.hpp.
Referenced by GeographicLib::AlbersEqualArea::AlbersEqualArea(), GeographicLib::DMS::Encode(), GeographicLib::Geocentric::Geocentric(), GeographicLib::Geodesic::Geodesic(), GeographicLib::GeodesicExact::GeodesicExact(), GeographicLib::LambertConformalConic::LambertConformalConic(), GeographicLib::NormalGravity::NormalGravity(), GeographicLib::PolarStereographic::PolarStereographic(), GeographicLib::LambertConformalConic::Reverse(), GeographicLib::PolarStereographic::SetScale(), GeographicLib::LambertConformalConic::SetScale(), GeographicLib::AlbersEqualArea::SetScale(), GeographicLib::Utility::str(), GeographicLib::TransverseMercator::TransverseMercator(), and GeographicLib::TransverseMercatorExact::TransverseMercatorExact().
static T GeographicLib::Math::NaN | ( | ) | [inline, static] |
The NaN (not a number)
T | the type of the returned value. |
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>().
static bool GeographicLib::Math::isnan | ( | T | x | ) | [inline, static] |
Test for NaN.
T | the type of the argument. |
[in] | x |
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().
static T GeographicLib::Math::infinity | ( | ) | [inline, static] |
Infinity
T | the type of the returned value. |
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>().
static T GeographicLib::Math::swab | ( | T | x | ) | [inline, static] |
const int GeographicLib::Math::extradigits [static] |
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
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().