Commit 27b303fec1eaea56cbd8b3c49264199a2ae3afb7
1 parent
f834a1a9
add modulus
Showing
2 changed files
with
32 additions
and
9 deletions
src/GTools.cpp
| ... | ... | @@ -56,3 +56,19 @@ std::string str(const int& value) |
| 56 | 56 | return s_value.str(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | + | |
| 60 | +/***********************************************************************//** | |
| 61 | + * @brief Returns the remainder of the division \a v1/v2. | |
| 62 | + * | |
| 63 | + * @param[in] v1 Argument 1. | |
| 64 | + * @param[in] v2 Argument 2. | |
| 65 | + * | |
| 66 | + * Returns the remainder of the division \a v1/v2. | |
| 67 | + * The result is non-negative. | |
| 68 | + * \a v1 can be positive or negative; \a v2 must be positive. | |
| 69 | + ***************************************************************************/ | |
| 70 | +double modulo(double v1, double v2) | |
| 71 | +{ | |
| 72 | + // Return | |
| 73 | + return (v1 >= 0) ? ((v1 < v2) ? v1 : fmod(v1,v2)) : (fmod(v1,v2)+v2); | |
| 74 | +} | ... | ... |
src/GTools.hpp
| ... | ... | @@ -15,23 +15,30 @@ |
| 15 | 15 | #define GTOOLS_HPP |
| 16 | 16 | |
| 17 | 17 | /* __ Includes ___________________________________________________________ */ |
| 18 | +#include <cmath> | |
| 18 | 19 | #include <string> |
| 19 | -//#include <sstream> // ostringstream | |
| 20 | -//#include <stdexcept> // exception | |
| 21 | 20 | |
| 22 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 23 | 22 | |
| 24 | 23 | /* __ Constants __________________________________________________________ */ |
| 25 | -const double pi = 3.1415926535897931159979635; | |
| 26 | -const double pihalf = pi/2.0; | |
| 27 | -const double twopi = 2.0*pi; | |
| 28 | -const double fourpi = 4.0*pi; | |
| 29 | -const double deg2rad = 0.0174532925199432954743717; | |
| 30 | -const double rad2deg = 57.295779513082322864647722; | |
| 31 | -const double ln10 = 2.3025850929940459010936138; | |
| 24 | +const double pi = 3.141592653589793238462643383279502884197; | |
| 25 | +const double twopi = 6.283185307179586476925286766559005768394; | |
| 26 | +const double fourpi = 12.56637061435917295385057353311801153679; | |
| 27 | +const double pihalf = 1.570796326794896619231321691639751442099; | |
| 28 | +const double inv_pihalf = 0.6366197723675813430755350534900574; | |
| 29 | +const double inv_sqrt4pi = 0.2820947917738781434740397257803862929220; | |
| 30 | +const double deg2rad = 0.0174532925199432954743717; | |
| 31 | +const double rad2deg = 57.295779513082322864647722; | |
| 32 | +const double ln2 = 0.6931471805599453094172321214581766; | |
| 33 | +const double ln10 = 2.3025850929940456840179914546843642; | |
| 34 | +const double inv_ln2 = 1.4426950408889634073599246810018921; | |
| 35 | +const double onethird = 1.0/3.0; | |
| 36 | +const double twothird = 2.0/3.0; | |
| 37 | +const double fourthird = 4.0/3.0; | |
| 32 | 38 | |
| 33 | 39 | /* __ Prototypes ________________________________________________________ */ |
| 34 | 40 | std::string strip_whitespace(const std::string& arg); |
| 35 | 41 | std::string str(const int& value); |
| 42 | +double modulo(double v1, double v2); | |
| 36 | 43 | |
| 37 | 44 | #endif /* GTOOLS_HPP */ | ... | ... |