Hermes
Numeric

Numerical classes provide all sort of number operations and functions. The hermes::Constants, for example, offer you common constants:

// Here are some constants provided by hermes
// and how you can access them
hermes::Constants::pi;
hermes::Constants::pi_over_four;
hermes::Constants::machine_epsilon;
// and more
Number functions.

Numbers

The hermes::Numbers namespace, included by hermes/numeric/numeric.h, provides lots of functions to work with floating-point, integer and binary number representations. Most functions are template functions. Here is an incomplete list of what you can find there, for more functions, please check the documentation of hermes::Numbers.

Trigonometry

A few trigonometric functions are listed in hermes::Trigonometry:

// Examples of trigonometric functions
hermes::Trigonometry::radians2degrees(hermes::Constants::two_pi);
static constexpr HERMES_DEVICE_CALLABLE real_t radians2degrees(real_t a)
Converts radians to degrees.
Definition: numeric.h:798
static HERMES_DEVICE_CALLABLE f32 safe_acos(f32 x)
Computes acos with clamped input.
Definition: numeric.h:810

Checks

You can make some floating-number comparisons as well using hermes::Check:

float x, y;
static constexpr bool is_between(T x, T a, T b)
Checks if a number is in a open interval.
Definition: numeric.h:866
static constexpr bool is_between_closed(T x, T a, T b)
Checks if a number is in a closed interval.
Definition: numeric.h:875
static constexpr HERMES_DEVICE_CALLABLE bool is_zero(T a)
Checks if number is 0.
Definition: numeric.h:834
static HERMES_DEVICE_CALLABLE std::enable_if_t< std::is_floating_point< T >::value, bool > is_nan(T v)
Checks if number representation is nan
Definition: numeric.h:884
static constexpr HERMES_DEVICE_CALLABLE bool is_equal(T a, T b)
Checks if two numbers are at most 1e-8 apart.
Definition: numeric.h:847

Interpolation

Check hermes::interpolation namespace for interpolation functions.

hermes::interpolation::smooth(a, b);
hermes::interpolation::smoothStep(a, b, v);
hermes::interpolation::sharpen(a, b);
hermes::interpolation::linearStep(v, a, b);
hermes::interpolation::mix(v, a, b);
hermes::interpolation::lerp(t, a, b);
// also bilerp and trilerp
hermes::interpolation::nearest(t, a, b);
hermes::monotonicCubicInterpolation(...);
Interpolation functions.

Arithmetic Interval

hermes::Interval represents a numeric interval that supports interval arithmetic. It is very useful when you want to represent your values considering the uncertainty that comes from the limitations of the computer representations of floating-point numbers. This way, hermes::Interval represents a closed interval [low, high] that guarantees to enclose your real numerical value, by providing all sorts of arithmetic operations of intervals.

int main() {
// suppose two intervals
hermes::Interval<f32> a(-1, 1), (0, 2);
// you can do common arithmetic (+,-,*,/)
auto c = a * b; // [-2,2]
// also
c.sqr(); // [0, 4]
c.sqrt(); // [nan, 1.41421]
return 0;
}
HERMES_DEVICE_CALLABLE Interval sqrt() const
Computes arithmetic interval square root.
Definition: interval.h:157
HERMES_DEVICE_CALLABLE Interval sqr() const
Computes arithmetic interval square.
Definition: interval.h:147
Numeric interval.

You can also make some queries:

a.contains(0); // true
a.center(); // 0
a.radius(); // 1
a.width(); // 2
a.isExact(); // false ([1,1] is exact)

EFloat

For certain calculations, you may want to keep track of floating-point operation errors accumulated over time. The hermes::EFloat class uses the hermes::Interval to carry error bounds during floating-point operations.

int main() {
// EFloats start as exact intervals
// in this case, [3,3] and [-1,-1]
hermes::EFloat a(3.f), b(-1.f);
// suppose you do math with them
auto c = a * 3 + a * b - 4 * b + a / b;
// the resulting quantity will contain errors
// that can be checked this way:
c.absoluteError(); // 1.14441e-05
c.upperBound(); // 7.00001
c.lowerBound(); // 6.99999
return 0;
}
Represents a value with error bounds.
Definition: e_float.h:47
Floating-point with attached error.