| Math.hpp | | Math.hpp | |
| /** | | /** | |
| * \file Math.hpp | | * \file Math.hpp | |
| * \brief Header for GeographicLib::Math class | | * \brief Header for GeographicLib::Math class | |
| * | | * | |
|
| * Copyright (c) Charles Karney (2008, 2009, 2010, 2011) <charles@karney.co | | * Copyright (c) Charles Karney (2008-2011) <charles@karney.com> and licens | |
| m> | | ed | |
| * and licensed under the MIT/X11 License. For more information, see | | * under the MIT/X11 License. For more information, see | |
| * http://geographiclib.sourceforge.net/ | | * http://geographiclib.sourceforge.net/ | |
| **********************************************************************/ | | **********************************************************************/ | |
| | | | |
| // Constants.hpp includes Math.hpp. Place this include outside Math.hpp's | | // Constants.hpp includes Math.hpp. Place this include outside Math.hpp's | |
| // include guard to enforce this ordering. | | // include guard to enforce this ordering. | |
| #include <GeographicLib/Constants.hpp> | | #include <GeographicLib/Constants.hpp> | |
| | | | |
| #if !defined(GEOGRAPHICLIB_MATH_HPP) | | #if !defined(GEOGRAPHICLIB_MATH_HPP) | |
|
| #define GEOGRAPHICLIB_MATH_HPP "$Id: f0c40ff3ed056d8a0a110725be4528be4a4a6a
6e $" | | #define GEOGRAPHICLIB_MATH_HPP "$Id: edd244e4c5c74e696096c2b6d598728957a0d3
6d $" | |
| | | | |
| /** | | /** | |
|
| * Are C++0X math functions available? | | * Are C++11 math functions available? | |
| **********************************************************************/ | | **********************************************************************/ | |
|
| #if !defined(GEOGRAPHICLIB_CPLUSPLUS0X_MATH) | | #if !defined(GEOGRAPHICLIB_CPLUSPLUS11_MATH) | |
| # if defined(__GXX_EXPERIMENTAL_CXX0X__) | | # if defined(__GXX_EXPERIMENTAL_CXX0X__) | |
|
| # define GEOGRAPHICLIB_CPLUSPLUS0X_MATH 1 | | # define GEOGRAPHICLIB_CPLUSPLUS11_MATH 1 | |
| # else | | # else | |
|
| # define GEOGRAPHICLIB_CPLUSPLUS0X_MATH 0 | | # define GEOGRAPHICLIB_CPLUSPLUS11_MATH 0 | |
| # endif | | # endif | |
| #endif | | #endif | |
| | | | |
| #if !defined(WORDS_BIGENDIAN) | | #if !defined(WORDS_BIGENDIAN) | |
| # define WORDS_BIGENDIAN 0 | | # define WORDS_BIGENDIAN 0 | |
| #endif | | #endif | |
| | | | |
| #if !defined(GEOGRAPHICLIB_PREC) | | #if !defined(GEOGRAPHICLIB_PREC) | |
| /** | | /** | |
| * The precision of floating point numbers used in %GeographicLib. 0 means | | * The precision of floating point numbers used in %GeographicLib. 0 means | |
| | | | |
| skipping to change at line 149 | | skipping to change at line 149 | |
| * @param[in] y | | * @param[in] y | |
| * @return sqrt(<i>x</i><sup>2</sup> + <i>y</i><sup>2</sup>). | | * @return sqrt(<i>x</i><sup>2</sup> + <i>y</i><sup>2</sup>). | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline T hypot(T x, T y) throw() { | | template<typename T> static inline T hypot(T x, T y) throw() { | |
| x = std::abs(x); | | x = std::abs(x); | |
| y = std::abs(y); | | y = std::abs(y); | |
| T a = (std::max)(x, y), | | T a = (std::max)(x, y), | |
| b = (std::min)(x, y) / (a ? a : 1); | | b = (std::min)(x, y) / (a ? a : 1); | |
| return a * std::sqrt(1 + b * b); | | return a * std::sqrt(1 + b * b); | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T hypot(T x, T y) throw() | | template<typename T> static inline T hypot(T x, T y) throw() | |
| { return std::hypot(x, y); } | | { return std::hypot(x, y); } | |
| #elif defined(_MSC_VER) | | #elif defined(_MSC_VER) | |
| static inline double hypot(double x, double y) throw() | | static inline double hypot(double x, double y) throw() | |
| { return _hypot(x, y); } | | { return _hypot(x, y); } | |
|
| #if (_MSC_VER < 1400) | | #if _MSC_VER < 1400 | |
| // Visual C++ 7.1/VS .NET 2003 does not have _hypotf() | | // Visual C++ 7.1/VS .NET 2003 does not have _hypotf() | |
| static inline float hypot(float x, float y) throw() | | static inline float hypot(float x, float y) throw() | |
| { return float(_hypot(x, y)); } | | { return float(_hypot(x, y)); } | |
| #else | | #else | |
| static inline float hypot(float x, float y) throw() | | static inline float hypot(float x, float y) throw() | |
| { return _hypotf(x, y); } | | { return _hypotf(x, y); } | |
| #endif | | #endif | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double hypot(long double x, long double y) throw() | | static inline long double hypot(long double x, long double y) throw() | |
| { return _hypot(x, y); } | | { return _hypot(x, y); } | |
| | | | |
| skipping to change at line 179 | | skipping to change at line 179 | |
| static inline double hypot(double x, double y) throw() | | static inline double hypot(double x, double y) throw() | |
| { return ::hypot(x, y); } | | { return ::hypot(x, y); } | |
| static inline float hypot(float x, float y) throw() | | static inline float hypot(float x, float y) throw() | |
| { return ::hypotf(x, y); } | | { return ::hypotf(x, y); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double hypot(long double x, long double y) throw() | | static inline long double hypot(long double x, long double y) throw() | |
| { return ::hypotl(x, y); } | | { return ::hypotl(x, y); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| /** | | /** | |
| * exp(\e x) - 1 accurate near \e x = 0. This is taken from | | * exp(\e x) - 1 accurate near \e x = 0. This is taken from | |
| * N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd | | * N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd | |
| * Edition (SIAM, 2002), Sec 1.14.1, p 19. | | * Edition (SIAM, 2002), Sec 1.14.1, p 19. | |
| * | | * | |
| * @tparam T the type of the argument and the returned value. | | * @tparam T the type of the argument and the returned value. | |
| * @param[in] x | | * @param[in] x | |
| * @return exp(\e x) - 1. | | * @return exp(\e x) - 1. | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline T expm1(T x) throw() { | | template<typename T> static inline T expm1(T x) throw() { | |
| volatile T | | volatile T | |
| y = std::exp(x), | | y = std::exp(x), | |
| z = y - 1; | | z = y - 1; | |
| // The reasoning here is similar to that for log1p. The expression | | // The reasoning here is similar to that for log1p. The expression | |
| // mathematically reduces to exp(x) - 1, and the factor z/log(y) = (y
- | | // mathematically reduces to exp(x) - 1, and the factor z/log(y) = (y
- | |
| // 1)/log(y) is a slowly varying quantity near y = 1 and is accuratel
y | | // 1)/log(y) is a slowly varying quantity near y = 1 and is accuratel
y | |
| // computed. | | // computed. | |
| return std::abs(x) > 1 ? z : (z == 0 ? x : x * z / std::log(y)); | | return std::abs(x) > 1 ? z : (z == 0 ? x : x * z / std::log(y)); | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T expm1(T x) throw() | | template<typename T> static inline T expm1(T x) throw() | |
| { return std::expm1(x); } | | { return std::expm1(x); } | |
| #else | | #else | |
| static inline double expm1(double x) throw() { return ::expm1(x); } | | static inline double expm1(double x) throw() { return ::expm1(x); } | |
| static inline float expm1(float x) throw() { return ::expm1f(x); } | | static inline float expm1(float x) throw() { return ::expm1f(x); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double expm1(long double x) throw() | | static inline long double expm1(long double x) throw() | |
| { return ::expm1l(x); } | | { return ::expm1l(x); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| /** | | /** | |
| * log(1 + \e x) accurate near \e x = 0. | | * log(1 + \e x) accurate near \e x = 0. | |
| * | | * | |
| * This is taken from D. Goldberg, | | * This is taken from D. Goldberg, | |
| * <a href="http://dx.doi.org/10.1145/103162.103163">What every compute
r | | * <a href="http://dx.doi.org/10.1145/103162.103163">What every compute
r | |
| * scientist should know about floating-point arithmetic</a> (1991), | | * scientist should know about floating-point arithmetic</a> (1991), | |
| * Theorem 4. See also, Higham (op. cit.), Answer to Problem 1.5, p 52
8. | | * Theorem 4. See also, Higham (op. cit.), Answer to Problem 1.5, p 52
8. | |
| * | | * | |
| * @tparam T the type of the argument and the returned value. | | * @tparam T the type of the argument and the returned value. | |
| * @param[in] x | | * @param[in] x | |
| | | | |
| skipping to change at line 234 | | skipping to change at line 234 | |
| template<typename T> static inline T log1p(T x) throw() { | | template<typename T> static inline T log1p(T x) throw() { | |
| volatile T | | volatile T | |
| y = 1 + x, | | y = 1 + x, | |
| z = y - 1; | | z = y - 1; | |
| // Here's the explanation for this magic: y = 1 + z, exactly, and z | | // Here's the explanation for this magic: y = 1 + z, exactly, and z | |
| // approx x, thus log(y)/z (which is nearly constant near z = 0) retu
rns | | // approx x, thus log(y)/z (which is nearly constant near z = 0) retu
rns | |
| // a good approximation to the true log(1 + x)/x. The multiplication
x * | | // a good approximation to the true log(1 + x)/x. The multiplication
x * | |
| // (log(y)/z) introduces little additional error. | | // (log(y)/z) introduces little additional error. | |
| return z == 0 ? x : x * std::log(y) / z; | | return z == 0 ? x : x * std::log(y) / z; | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T log1p(T x) throw() | | template<typename T> static inline T log1p(T x) throw() | |
| { return std::log1p(x); } | | { return std::log1p(x); } | |
| #else | | #else | |
| static inline double log1p(double x) throw() { return ::log1p(x); } | | static inline double log1p(double x) throw() { return ::log1p(x); } | |
| static inline float log1p(float x) throw() { return ::log1pf(x); } | | static inline float log1p(float x) throw() { return ::log1pf(x); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double log1p(long double x) throw() | | static inline long double log1p(long double x) throw() | |
| { return ::log1pl(x); } | | { return ::log1pl(x); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| /** | | /** | |
| * The inverse hyperbolic sine function. This is defined in terms of | | * The inverse hyperbolic sine function. This is defined in terms of | |
| * Math::log1p(\e x) in order to maintain accuracy near \e x = 0. In | | * Math::log1p(\e x) in order to maintain accuracy near \e x = 0. In | |
| * addition, the odd parity of the function is enforced. | | * addition, the odd parity of the function is enforced. | |
| * | | * | |
| * @tparam T the type of the argument and the returned value. | | * @tparam T the type of the argument and the returned value. | |
| * @param[in] x | | * @param[in] x | |
| * @return asinh(\e x). | | * @return asinh(\e x). | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline T asinh(T x) throw() { | | template<typename T> static inline T asinh(T x) throw() { | |
| T y = std::abs(x); // Enforce odd parity | | T y = std::abs(x); // Enforce odd parity | |
| y = log1p(y * (1 + y/(hypot(T(1), y) + 1))); | | y = log1p(y * (1 + y/(hypot(T(1), y) + 1))); | |
| return x < 0 ? -y : y; | | return x < 0 ? -y : y; | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T asinh(T x) throw() | | template<typename T> static inline T asinh(T x) throw() | |
| { return std::asinh(x); } | | { return std::asinh(x); } | |
| #else | | #else | |
| static inline double asinh(double x) throw() { return ::asinh(x); } | | static inline double asinh(double x) throw() { return ::asinh(x); } | |
| static inline float asinh(float x) throw() { return ::asinhf(x); } | | static inline float asinh(float x) throw() { return ::asinhf(x); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double asinh(long double x) throw() | | static inline long double asinh(long double x) throw() | |
| { return ::asinhl(x); } | | { return ::asinhl(x); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| /** | | /** | |
| * The inverse hyperbolic tangent function. This is defined in terms o
f | | * The inverse hyperbolic tangent function. This is defined in terms o
f | |
| * Math::log1p(\e x) in order to maintain accuracy near \e x = 0. In | | * Math::log1p(\e x) in order to maintain accuracy near \e x = 0. In | |
| * addition, the odd parity of the function is enforced. | | * addition, the odd parity of the function is enforced. | |
| * | | * | |
| * @tparam T the type of the argument and the returned value. | | * @tparam T the type of the argument and the returned value. | |
| * @param[in] x | | * @param[in] x | |
| * @return atanh(\e x). | | * @return atanh(\e x). | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline T atanh(T x) throw() { | | template<typename T> static inline T atanh(T x) throw() { | |
| T y = std::abs(x); // Enforce odd parity | | T y = std::abs(x); // Enforce odd parity | |
| y = log1p(2 * y/(1 - y))/2; | | y = log1p(2 * y/(1 - y))/2; | |
| return x < 0 ? -y : y; | | return x < 0 ? -y : y; | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T atanh(T x) throw() | | template<typename T> static inline T atanh(T x) throw() | |
| { return std::atanh(x); } | | { return std::atanh(x); } | |
| #else | | #else | |
| static inline double atanh(double x) throw() { return ::atanh(x); } | | static inline double atanh(double x) throw() { return ::atanh(x); } | |
| static inline float atanh(float x) throw() { return ::atanhf(x); } | | static inline float atanh(float x) throw() { return ::atanhf(x); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double atanh(long double x) throw() | | static inline long double atanh(long double x) throw() | |
| { return ::atanhl(x); } | | { return ::atanhl(x); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| /** | | /** | |
| * The cube root function. | | * The cube root function. | |
| * | | * | |
| * @tparam T the type of the argument and the returned value. | | * @tparam T the type of the argument and the returned value. | |
| * @param[in] x | | * @param[in] x | |
| * @return the real cube root of \e x. | | * @return the real cube root of \e x. | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline T cbrt(T x) throw() { | | template<typename T> static inline T cbrt(T x) throw() { | |
| T y = std::pow(std::abs(x), 1/T(3)); // Return the real cube root | | T y = std::pow(std::abs(x), 1/T(3)); // Return the real cube root | |
| return x < 0 ? -y : y; | | return x < 0 ? -y : y; | |
| } | | } | |
|
| #elif GEOGRAPHICLIB_CPLUSPLUS0X_MATH | | #elif GEOGRAPHICLIB_CPLUSPLUS11_MATH | |
| template<typename T> static inline T cbrt(T x) throw() | | template<typename T> static inline T cbrt(T x) throw() | |
| { return std::cbrt(x); } | | { return std::cbrt(x); } | |
| #else | | #else | |
| static inline double cbrt(double x) throw() { return ::cbrt(x); } | | static inline double cbrt(double x) throw() { return ::cbrt(x); } | |
| static inline float cbrt(float x) throw() { return ::cbrtf(x); } | | static inline float cbrt(float x) throw() { return ::cbrtf(x); } | |
| #if defined(HAVE_LONG_DOUBLE) | | #if defined(HAVE_LONG_DOUBLE) | |
| static inline long double cbrt(long double x) throw() { return ::cbrtl(
x); } | | static inline long double cbrt(long double x) throw() { return ::cbrtl(
x); } | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
| /** | | /** | |
| * Test for finiteness. | | * Test for finiteness. | |
| * | | * | |
| * @tparam T the type of the argument. | | * @tparam T the type of the argument. | |
| * @param[in] x | | * @param[in] x | |
| * @return true if number is finite, false if NaN or infinite. | | * @return true if number is finite, false if NaN or infinite. | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline bool isfinite(T x) throw() { | | template<typename T> static inline bool isfinite(T x) throw() { | |
| #if defined(DOXYGEN) | | #if defined(DOXYGEN) | |
| return std::abs(x) <= (std::numeric_limits<T>::max)(); | | return std::abs(x) <= (std::numeric_limits<T>::max)(); | |
|
| #elif (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MATH) | | #elif (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MATH) | |
| return _finite(x) != 0; | | return _finite(x) != 0; | |
| #else | | #else | |
| return std::isfinite(x); | | return std::isfinite(x); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| /** | | /** | |
| * The NaN (not a number) | | * The NaN (not a number) | |
| * | | * | |
| * @tparam T the type of the returned value. | | * @tparam T the type of the returned value. | |
| | | | |
| skipping to change at line 364 | | skipping to change at line 364 | |
| static inline real NaN() throw() { return NaN<real>(); } | | static inline real NaN() throw() { return NaN<real>(); } | |
| | | | |
| /** | | /** | |
| * Test for NaN. | | * Test for NaN. | |
| * | | * | |
| * @tparam T the type of the argument. | | * @tparam T the type of the argument. | |
| * @param[in] x | | * @param[in] x | |
| * @return true if argument is a NaN. | | * @return true if argument is a NaN. | |
| **********************************************************************
/ | | **********************************************************************
/ | |
| template<typename T> static inline bool isnan(T x) throw() { | | template<typename T> static inline bool isnan(T x) throw() { | |
|
| #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS0X_MA
TH) | | #if defined(DOXYGEN) || (defined(_MSC_VER) && !GEOGRAPHICLIB_CPLUSPLUS11_MA
TH) | |
| return x != x; | | return x != x; | |
| #else | | #else | |
| return std::isnan(x); | | return std::isnan(x); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Infinity | | * Infinity | |
| * | | * | |
| * @tparam T the type of the returned value. | | * @tparam T the type of the returned value. | |
| | | | |
End of changes. 20 change blocks. |
| 22 lines changed or deleted | | 22 lines changed or added | |
|
| SphericalEngine.hpp | | SphericalEngine.hpp | |
| | | | |
| skipping to change at line 12 | | skipping to change at line 12 | |
| * \file SphericalEngine.hpp | | * \file SphericalEngine.hpp | |
| * \brief Header for GeographicLib::SphericalEngine class | | * \brief Header for GeographicLib::SphericalEngine class | |
| * | | * | |
| * Copyright (c) Charles Karney (2011, 2012) <charles@karney.com> and licen
sed | | * Copyright (c) Charles Karney (2011, 2012) <charles@karney.com> and licen
sed | |
| * under the MIT/X11 License. For more information, see | | * under the MIT/X11 License. For more information, see | |
| * http://geographiclib.sourceforge.net/ | | * http://geographiclib.sourceforge.net/ | |
| **********************************************************************/ | | **********************************************************************/ | |
| | | | |
| #if !defined(GEOGRAPHICLIB_SPHERICALENGINE_HPP) | | #if !defined(GEOGRAPHICLIB_SPHERICALENGINE_HPP) | |
| #define GEOGRAPHICLIB_SPHERICALENGINE_HPP \ | | #define GEOGRAPHICLIB_SPHERICALENGINE_HPP \ | |
|
| "$Id: dae9ba0d660c070c0f28715de87ed20f79808793 $" | | "$Id: f48320a694ecf901d997b23d32ea625e589f9534 $" | |
| | | | |
| #include <vector> | | #include <vector> | |
| #include <istream> | | #include <istream> | |
| #include <GeographicLib/Constants.hpp> | | #include <GeographicLib/Constants.hpp> | |
| | | | |
| #if defined(_MSC_VER) | | #if defined(_MSC_VER) | |
| // Squelch warnings about dll vs vector | | // Squelch warnings about dll vs vector | |
| #pragma warning (push) | | #pragma warning (push) | |
| #pragma warning (disable: 4251) | | #pragma warning (disable: 4251) | |
| #endif | | #endif | |
| | | | |
| skipping to change at line 127 | | skipping to change at line 127 | |
| * be large enough to hold the coefficients. Otherwise an exception
is | | * be large enough to hold the coefficients. Otherwise an exception
is | |
| * thrown. | | * thrown. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| coeff(const std::vector<real>& C, | | coeff(const std::vector<real>& C, | |
| const std::vector<real>& S, | | const std::vector<real>& S, | |
| int N, int nmx, int mmx) | | int N, int nmx, int mmx) | |
| : _N(N) | | : _N(N) | |
| , _nmx(nmx) | | , _nmx(nmx) | |
| , _mmx(mmx) | | , _mmx(mmx) | |
| , _Cnm(C.begin()) | | , _Cnm(C.begin()) | |
|
| , _Snm(S.begin() - (_N + 1)) | | , _Snm(S.begin()) | |
| { | | { | |
| if (!(_N >= _nmx && _nmx >= _mmx && _mmx >= -1)) | | if (!(_N >= _nmx && _nmx >= _mmx && _mmx >= -1)) | |
| throw GeographicErr("Bad indices for coeff"); | | throw GeographicErr("Bad indices for coeff"); | |
| if (!(index(_nmx, _mmx) < int(C.size()) && | | if (!(index(_nmx, _mmx) < int(C.size()) && | |
| index(_nmx, _mmx) < int(S.size()) + (_N + 1))) | | index(_nmx, _mmx) < int(S.size()) + (_N + 1))) | |
| throw GeographicErr("Arrays too small in coeff"); | | throw GeographicErr("Arrays too small in coeff"); | |
| SphericalEngine::RootTable(_nmx); | | SphericalEngine::RootTable(_nmx); | |
| } | | } | |
| /** | | /** | |
| * The constructor for full coefficient vectors. | | * The constructor for full coefficient vectors. | |
| | | | |
| skipping to change at line 153 | | skipping to change at line 153 | |
| * This requires \e N >= -1. \e C and \e S must also be large enough
to | | * This requires \e N >= -1. \e C and \e S must also be large enough
to | |
| * hold the coefficients. Otherwise an exception is thrown. | | * hold the coefficients. Otherwise an exception is thrown. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| coeff(const std::vector<real>& C, | | coeff(const std::vector<real>& C, | |
| const std::vector<real>& S, | | const std::vector<real>& S, | |
| int N) | | int N) | |
| : _N(N) | | : _N(N) | |
| , _nmx(N) | | , _nmx(N) | |
| , _mmx(N) | | , _mmx(N) | |
| , _Cnm(C.begin()) | | , _Cnm(C.begin()) | |
|
| , _Snm(S.begin() - (_N + 1)) | | , _Snm(S.begin()) | |
| { | | { | |
| if (!(_N >= -1)) | | if (!(_N >= -1)) | |
| throw GeographicErr("Bad indices for coeff"); | | throw GeographicErr("Bad indices for coeff"); | |
| if (!(index(_nmx, _mmx) < int(C.size()) && | | if (!(index(_nmx, _mmx) < int(C.size()) && | |
| index(_nmx, _mmx) < int(S.size()) + (_N + 1))) | | index(_nmx, _mmx) < int(S.size()) + (_N + 1))) | |
| throw GeographicErr("Arrays too small in coeff"); | | throw GeographicErr("Arrays too small in coeff"); | |
| SphericalEngine::RootTable(_nmx); | | SphericalEngine::RootTable(_nmx); | |
| } | | } | |
| /** | | /** | |
| * @return \e N the degree giving storage layout for \e C and \e S. | | * @return \e N the degree giving storage layout for \e C and \e S. | |
| | | | |
| skipping to change at line 196 | | skipping to change at line 196 | |
| * @param[in] k the one-dimensional index. | | * @param[in] k the one-dimensional index. | |
| * @return the value of the \e C coefficient. | | * @return the value of the \e C coefficient. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| inline Math::real Cv(int k) const { return *(_Cnm + k); } | | inline Math::real Cv(int k) const { return *(_Cnm + k); } | |
| /** | | /** | |
| * An element of \e S. | | * An element of \e S. | |
| * | | * | |
| * @param[in] k the one-dimensional index. | | * @param[in] k the one-dimensional index. | |
| * @return the value of the \e S coefficient. | | * @return the value of the \e S coefficient. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
|
| inline Math::real Sv(int k) const { return *(_Snm + k); } | | inline Math::real Sv(int k) const { return *(_Snm + (k - (_N + 1)));
} | |
| /** | | /** | |
| * An element of \e C with checking. | | * An element of \e C with checking. | |
| * | | * | |
| * @param[in] k the one-dimensional index. | | * @param[in] k the one-dimensional index. | |
| * @param[in] n the requested degree. | | * @param[in] n the requested degree. | |
| * @param[in] m the requested order. | | * @param[in] m the requested order. | |
| * @param[in] f a multiplier. | | * @param[in] f a multiplier. | |
| * @return the value of the \e C coefficient multiplied by \e f in \e
n | | * @return the value of the \e C coefficient multiplied by \e f in \e
n | |
| * and \e m are in range else 0. | | * and \e m are in range else 0. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| | | | |
| skipping to change at line 220 | | skipping to change at line 220 | |
| * An element of \e S with checking. | | * An element of \e S with checking. | |
| * | | * | |
| * @param[in] k the one-dimensional index. | | * @param[in] k the one-dimensional index. | |
| * @param[in] n the requested degree. | | * @param[in] n the requested degree. | |
| * @param[in] m the requested order. | | * @param[in] m the requested order. | |
| * @param[in] f a multiplier. | | * @param[in] f a multiplier. | |
| * @return the value of the \e S coefficient multiplied by \e f in \e
n | | * @return the value of the \e S coefficient multiplied by \e f in \e
n | |
| * and \e m are in range else 0. | | * and \e m are in range else 0. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| inline Math::real Sv(int k, int n, int m, real f) const | | inline Math::real Sv(int k, int n, int m, real f) const | |
|
| { return m > _mmx || n > _nmx ? 0 : *(_Snm + k) * f; } | | { return m > _mmx || n > _nmx ? 0 : *(_Snm + (k - (_N + 1))) * f; } | |
| | | | |
| /** | | /** | |
| * The size of the coefficient vector for the cosine terms. | | * The size of the coefficient vector for the cosine terms. | |
| * | | * | |
| * @param[in] N the maximum degree. | | * @param[in] N the maximum degree. | |
| * @param[in] M the maximum order. | | * @param[in] M the maximum order. | |
| * @return the size of the vector of cosine terms as stored in column | | * @return the size of the vector of cosine terms as stored in column | |
| * major order. | | * major order. | |
| ********************************************************************
**/ | | ********************************************************************
**/ | |
| static inline int Csize(int N, int M) | | static inline int Csize(int N, int M) | |
| | | | |
End of changes. 5 change blocks. |
| 5 lines changed or deleted | | 5 lines changed or added | |
|