Core Library Utilities#
- group Utilities
This module contains basic core library utilities, such as an ergonomic way to silence unused argument warnings and comparison functions that eliminate the pitfalls associated with comparing signed and unsigned types and/or floating point numbers.
Functions
-
template<typename ...Args>
constexpr auto ignore(Args&&... args) noexcept -> void# Utility function to ignore the given values.
Example#
auto my_func(i32 arg1, i32 arg2, i32 arg3) -> void { // TODO: Implement this! // eliminate unused argument warnings/errors during compilation ignore(arg1, arg2, arg3); }
- Template Parameters:
Args – - The types of the things to ignore
- Parameters:
args – - The things to ignore
-
template<typename ...Args>
- group Safe Comparison Functions
Hyperion provides safe comparison functions for safely comparing any types providing comparison operators, including floating point types, as well as mixed comparisons between signed, unsigned, and floating point types.
Example#
using hyperion::operator""_f32; const auto my_f32 = 12'345.6789_f32; const auto my_other_f32 = 11'345.6789_f32; const auto is_equal = hyperion::equality_compare(my_f32, my_other_f32);
Enums
-
enum class EpsilonType : bool#
Types of epsilons usable in floating point comparisons, either
Absolute, i.e. a fixed magnitude difference, orRelative, i.e. a percentage magnitude difference.Example#
static constexpr auto my_epsilon = make_epsilon<EpsilonType::Relative>{0.1_f64};
Values:
-
enumerator Absolute#
-
enumerator Relative#
-
enumerator Absolute#
Functions
-
template<EpsilonType TType, Arithmetic TEpsilon>
constexpr auto make_epsilon(TEpsilon &&epsilon) -> Epsilon<TType, TEpsilon># Returns an
Epsilonof the specifiedEpsilonTypeand given value.Example#
static constexpr auto my_epsilon = make_epsilon<EpsilonType::Relative>{0.1_f64};
- Template Parameters:
TType – The
EpsilonTypeof the epsilonTEpsilon – The arithmetic type of the epsilon (e.g.,
f64, orint)
- Parameters:
epsilon – the arithmetic value of the epsilon (e.g.
0.001_f64)- Returns:
The
Epsilon
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto equality_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares
lhsandrhsfor equality, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 and value2 are within 10% of whichever is largest auto is_equal = equality_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsandrhsare equal
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto inequality_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares
lhsandrhsfor inequality, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 and value2 are _not_ within 10% of whichever is largest auto is_equal = inequality_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsandrhsare not equal
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto less_than_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares whether
lhsis less thanrhs, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 is less than value2 by at least 10% auto is_equal = less_than_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsis less thanrhs
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto less_than_or_equal_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares whether
lhsis less than or equal torhs, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 is less than value2 by at least 10%, // or that value1 and value2 are within 10% of whichever is largest auto is_equal = less_than_or_equal_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsis less than or equal torhs
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto greater_than_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares whether
lhsis greater thanrhs, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 is greater than value2 by at least 10% auto is_equal = greater_than_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsis greater thanrhs
-
template<typename TLhs, typename TRhs, EpsilonKind TEpsilon = decltype(detail::make_epsilon<TLhs, TRhs>())>
constexpr auto greater_than_or_equal_compare(TLhs &&lhs, TRhs &&rhs, TEpsilon epsilon = detail::make_epsilon<TLhs, TRhs>()) noexcept(noexcept(lhs == rhs) && noexcept(rhs == lhs)) -> bool# Safely compares whether
lhsis greater than or equal torhs, taking into account signedness differences and accounting for floating point inaccuracies with anEpsilonExample#
constexpr auto my_epsilon = Epsilon<EpsilonType::Relative>{0.1_f64}; auto value1 = getSomeValue(1); auto value2 = getSomeValue(2); // check that value1 is greater than value2 by at least 10%, // or that value1 and value2 are within 10% of whichever is largest auto is_equal = less_than_or_equal_compare(value1, value2, my_epsilon);
- Template Parameters:
TLhs – The type of the left-hand argument in the comparison
TRhs – The type of the right-hand argument in the comparison Defaults to an
Absoluteepsilon of typefmax.
- Parameters:
lhs – The left-hand argument in the comparison
rhs – The right-hand argument in the comparison
epsilon – The
Epsilonused for floating point comparison. Defaults to anAbsoluteepsilon equal to the machine epsilon corresponding with the type that is the wider of the two typesTLhsandTRhs.
- Returns:
Whether
lhsis greater than or equal torhs
Variables
-
template<typename TType>
static constexpr auto is_epsilon_specialization_v = is_epsilon_specialization<TType>::value# Value of the type trait
is_epsilon_specialization. Used to check whetherTTypeis a specialization ofEpsilon- Template Parameters:
TType – The type to check
-
template<EpsilonType TType = EpsilonType::Absolute, Arithmetic TNumeric = fmax>
class Epsilon# - #include <hyperion/platform/compare.h>
Represents an
AbsoluteorRelativeepsilon of a specificArithmetictype.Example#
static constexpr auto my_epsilon = make_epsilon<EpsilonType::Relative>{0.1_f64};
- Template Parameters:
Public Functions
-
inline explicit(false) const expr Epsilon(TNumeric val)#
Constructs an
Epsilonwith the given numeric value.- Parameters:
val – The numeric value of this
Epsilon
-
inline constexpr auto epsilon(const Arithmetic auto &lhs, const Arithmetic auto &rhs) const noexcept -> TNumeric#
Returns the
Absoluteepsilon thisEpsilonwould represent when used in a comparison between the two arguments.- Parameters:
lhs – The left-hand argument of the theoretical comparsion
rhs – The right-hand argument of the theoretical comparsion
- Returns:
The
Absoluteepsilon thisEpsilonrepresents when used in a comparision betweenlhsandrhs
-
enum class EpsilonType : bool#
-
template<typename TLhs, typename TRhs>
concept EqualityComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis equality comparable with aTRhs
-
template<typename TLhs, typename TRhs>
concept InequalityComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis inequality comparable with aTRhs
-
template<typename TLhs, typename TRhs>
concept LessThanComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis less-than comparable with aTRhs
-
template<typename TLhs, typename TRhs>
concept LessThanOrEqualComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis less-than-or-equal comparable with aTRhs
-
template<typename TLhs, typename TRhs>
concept GreaterThanComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis greater-than comparable with aTRhs
-
template<typename TLhs, typename TRhs>
concept GreaterThanOrEqualComparable# - #include <hyperion/platform/compare.h>
Concept definition requiring that a
TLhsis greater-than-or-equal comparable with aTRhs
Warning
doxygenconcept: Cannot find concept “hyperion::platform::compare::ThreeWayComparable” in doxygen xml output for project “hyperion::platform” from directory: _build/xml
-
template<typename TType>
concept Arithmetic# - #include <hyperion/platform/compare.h>
Concept definition requiring that a type is truly arithmetic (a non-character, non-boolean integer type or floating point type)
-
template<typename TType>
concept EpsilonKind# - #include <hyperion/platform/compare.h>
Concept requiring that
TTypeis a specialization ofEpsilon