ICAROUS
|
#include <Util.h>
Public Member Functions | |
int | mod (int x, int y) |
Static Public Member Functions | |
static bool | almost_less (double a, double b) |
static bool | almost_less (double a, double b, INT64FM maxUlps) |
static bool | almost_greater (double a, double b) |
static bool | almost_greater (double a, double b, INT64FM maxUlps) |
static bool | almost_geq (double a, double b, INT64FM maxUlps) |
static bool | almost_geq (double a, double b) |
static bool | almost_leq (double a, double b, INT64FM maxUlps) |
static bool | almost_leq (double a, double b) |
static bool | almost_equals (double a, double b, INT64FM maxUlps) |
static bool | almost_equals (double a, double b) |
static bool | within_epsilon (double a, double b, double epsilon) |
static bool | within_epsilon (double a, double epsilon) |
static double | discretizeDir (double voz, double nvoz, double discreteUnits) |
static double | sq (const double x) |
static INT64FM | llabs (const INT64FM x) |
static double | sqrt_safe (const double x) |
static double | atan2_safe (const double y, const double x) |
** More... | |
static double | asin_safe (double x) |
static double | acos_safe (double x) |
static double | discr (const double a, const double b, const double c) |
static double | root (const double a, const double b, const double c, int eps) |
static double | root2b (const double a, const double b, const double c, const int eps) |
static int | sign (const double x) |
static int | signTriple (const double x) |
static const double & | min (const double &x, const double &y) |
static const float & | min (const float &x, const float &y) |
static const int & | min (const int &x, const int &y) |
static const long & | min (const long &x, const long &y) |
static const double & | max (const double &x, const double &y) |
static const float & | max (const float &x, const float &y) |
static const int & | max (const int &x, const int &y) |
static const long & | max (const long &x, const long &y) |
static double | modulo (double val, double mod) |
static double | safe_modulo (double val, double mod) |
static double | to_pi (double rad) |
static double | to_360 (double deg) |
static double | to_2pi (double rad) |
static double | to_pi2_cont (double rad) |
static double | to_180 (double deg) |
static bool | less_or_equal (std::string s1, std::string s2) |
static bool | clockwise (double alpha, double beta) |
static int | turnDir (double initTrack, double goalTrack) |
static double | turnDelta (double alpha, double beta) |
static double | signedTurnDelta (double alpha, double beta) |
static double | turnDelta (double alpha, double beta, bool turnRight) |
static double | turnDelta (double alpha, double beta, int dir) |
static bool | is_double (const std::string &str) |
static bool | is_boolean (const std::string &s) |
static double | parse_double (const std::string &str) |
static double | decimalDegrees (const std::string °MinSec) |
static double | parse_time (const std::string &s) |
static std::string | hoursMinutesSeconds (double t) |
A broad collection of utility functions
|
static |
a safe (won't return NaN or throw exceptions) version of arc-cosine
x | angle |
|
static |
Are these two numbers almost equal, given the PRECISION_DEFAULT
a | one number |
b | another number |
|
static |
Determines if these two doubles, relative to each other, are almost equal. The "nearness" metric is captured in maxUlps. Mathematically, a == b is the same as a - b == 0. Due to quirks in floating point, generally almostEquals(a, b) is not the same as almostEquals(a - b, 0). The form without the subtraction is preferred.
Consistent with the IEEE-754 floating point specification, "not a number" (NaN) won't compare as equal to anything (including itself or another NaN).
If two doubles are almost_equals() with a maxUlps parameter of 16348, then this means there can be at most 16347 floating point numbers between them. A value of 16348 for "units of least precision" (ulps) corresponds to a and b agreeing to about 13 decimal places. Said another way, the two numbers have an absolute difference of (approximately) 1e-13 if the two floating point numbers are near 1.
The maxUlps parameter must be positive and smaller than 2^50
The implementation is based on the discussion (but not the code) in (google: comparing floats cygnus)
a | one number |
b | another number |
maxUlps | the precision, or more specifically, the maximum units of least precision |
|
static |
Determines if a is greater than or almost equal to b, according to the definition of the almostEquals() method.
a | one number |
b | another number |
|
static |
Determines if a is greater than or almost equal to b, according to the definition of the almostEquals() method.
a | one number |
b | another number |
maxUlps | maximum units of least precision |
|
static |
Determines if a > b, without being almost equal, according to the definition of the almostEquals() method.
a | one number |
b | another number |
|
static |
Determines if a > b, without being almost equal, according to the definition of the almostEquals() method.
a | one number |
b | another number |
maxUlps | maximum units of least precision |
|
static |
Determines if a is less than or almost equal to b, according to the definition of the almostEquals() method.
a | one number |
b | another number |
|
static |
Determines if a is less than or almost equal to b, according to the definition of the almostEquals() method.
a | one number |
b | another number |
maxUlps | maximum units of least precision |
|
static |
Determines if a < b, without being almost equal, according to the definition of the almostEquals() method..
a | one number |
b | another number |
|
static |
Determines if a < b, without being almost equal, according to the definition of the almostEquals() method..
a | one number |
b | another number |
maxUlps | maximum units of least precision |
|
static |
a safe (won't return NaN or throw exceptions) version of arc-sine
x | value |
|
static |
a safe (won't return NaN or throw exceptions) version of arc-tangent
y | ordinate coordinate |
x | abscissa coordinate |
|
static |
Returns true if a turn from track angle alpha to track angle beta is clockwise (by the shortest path). If the two angles are equal, then this function returns true.
alpha | one angle |
beta | another angle |
|
static |
degMinSec | Lat/Lon String of the form "46:55:00" or "-111:57:00" |
degMinSec | Lat/Lon string of the form "46:55:00" or "-111:57:00" |
|
static |
Discriminant of a quadratic
a | a coefficient of quadratic |
b | b coefficient of quadratic |
c | c coefficient of quadratic |
|
static |
Discretize the value of nvoz in the direction from voz in units of discreteUnits
voz | The value nvoz was derived from |
nvoz | The value to be discretized |
discreteUnits | the size of discretization, e.g. 0.1, 1.0, 10.0, 100.0 etc |
|
static |
Convert the decimal time (in seconds) into a 0:00:00 string. This prints as many digits as necessary for the hours (one or two, typically). See time_str(double) for an alternate format.
t | time in seconds |
t | time in seconds |
|
static |
Returns true if the stored value for key is likely a boolean
s | name |
|
static |
Returns true if string s1 is less than or equal to string s2.
s1 | one string |
s2 | another string |
|
static |
return the absolute value
|
static |
A maximum function that has the same behavior as the Java Math.max function: NaN is propagated for both x and y, and -0.0 is "less than" +0.0 Note that std::max(double,double) does NOT have the same behavior, especially if NaN is involved!
|
static |
A minimum function that has the same behavior as the Java Math.min function: NaN is propagated for both x and y, and -0.0 is "less than" +0.0 Note that std::min(double,double) does NOT have the same behavior, especially if NaN is involved!
int larcfm::Util::mod | ( | int | x, |
int | y | ||
) |
The behavior of the xy operator is different between Java and C++ if either x or y is negative. Use this to always return a value between 0 and y.
x | value |
y | range |
|
static |
Computes the modulo of val and mod. The returned value is in the range [0,mod)
val | numerator |
mod | denominator, assumed/required to be non-zero |
Computes the modulo of val and mod. The returned value is in the range [0,mod)
val | numerator |
mod | denominator |
|
static |
Returns a double value which is a representation of the given string. If the string does not represent a number, an arbitrary value is returned. In many cases, but not all, if the string is not a number then 0.0 is returned. However, on some platforms, "1abc" will return 1. If one wants to know the fact that the string is not a number, then use Util.is_double() method.
|
static |
Reads in a clock string and converts it to seconds. Accepts hh:mm:ss, mm:ss, and ss.
s | string value |
Reads in a clock string and converts it to seconds. Accepts hh:mm:ss, mm:ss, and ss.
|
static |
Quadratic equation, eps = -1 or +1
a | a coefficient of quadratic |
b | b coefficient of quadratic |
c | c coefficient of quadratic |
eps | -1 or +1 (to indicate which solution you want) |
|
static |
root2b(a,b,c,eps) = root(a,2*b,c,eps) , eps = -1 or +1
a | a coefficient of quadratic |
b | b coefficient of quadratic |
c | c coefficient of quadratic |
eps | -1 or +1 (to indicate which solution you want) |
|
static |
Computes the modulo of val and mod. If mod > 0, the returned value is in the r ange [0,mod). Otherwise, returns val.
val | numerator |
mod | denominator |
|
static |
Returns +1 if the argument is positive or 0, -1 otherwise. Note: This is not the classic signum function from mathematics that returns 0 when a 0 is supplied.
x | value |
|
static |
Returns the smallest angle between two track angles [-PI,PI]. The sign indicates the direction of the turn, positive is clockwise, negative counterclockwise.
alpha | one angle |
beta | another angle |
|
static |
Return +1 if the value is greater than 0, -1 if it is less than 0, or 0.
x | value to be checked |
|
static |
Square
x | value |
|
static |
a safe (won't return NaN or throw exceptions) version of square root
x | value |
|
static |
Converts deg
degrees to the range (-180
, 180
].
deg | Degrees |
deg
in the range (-180
, 180
].
|
static |
Converts rad
radians to the range [0
, 2*pi
].
Note: this should not be used for argument reduction for trigonometric functions (Math.sin(to_2pi(x)). Bad roundoff errors could occur.
rad | Radians |
rad
in the range [0
, 2*pi
).
|
static |
Converts deg
degrees to the range [0
, 360
).
deg | Degrees |
deg
in the range [0
, 360
).
|
static |
Converts rad
radians to the range (-pi
, pi
].
Note: this should not be used for argument reduction for trigonometric functions (Math.sin(to_pi(x))
rad | Radians |
rad
in the range (-pi
, pi
].
|
static |
Converts rad
radians to the range [-Math.PI/2
, Math.PI/2
). This function is continuous, so to_pi2_cont(PI/2+eps) equals PI/2-eps.
rad | Radians |
rad
in the range [-Math.PI/2
, Math.PI/2
).
|
static |
Returns the smallest angle between two track angles [0,PI]. Reminder: This is also the angle from BOT to EOT from the point of view of the turn center.
It is not angle between two segments from the vertex's point of view.
alpha | one angle |
beta | another angle |
|
static |
Returns the angle between two tracks when turning in direction indicated by turnRight flag [0,2PI] Note: this function can return an angle larger than PI!
alpha | one angle |
beta | another angle |
turnRight | when true, measure angles from the right |
|
static |
Returns the angle between two tracks when turning in direction indicated by turnRight flag [0,2PI] Note: this function can return an angle larger than PI!
alpha | one angle |
beta | another angle |
dir | = +/- 1 + right, - left |
|
static |
Returns 1 if the minimal turn to goalTrack (i.e. less than pi) is to the right, else -1
initTrack | initial track [rad] |
goalTrack | target track [rad] |
|
static |
Comparison of two values to determine if their absolute difference is within a value epsilon. If the epsilon value is too small relative to the a and b values in question, then this is essentially the same as ==. Epsilon must be positive.
a | one number |
b | another number |
epsilon | maximum difference |
|
static |
Returns true if the magnitude of a is less than epsilon. Epsilon must be positive.
a | a number |
epsilon | maximum value |