Stratax 0.4.0rc1
Loading...
Searching...
No Matches
NumericValidation.hpp File Reference

Shared validation for division operands and integral shift counts. More...

#include <stratax/core/dtypes/Concepts.hpp>
#include <stratax/exceptions/Exceptions.hpp>
#include <climits>
#include <cstdint>
#include <limits>
#include <type_traits>
Include dependency graph for NumericValidation.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<Numeric L, Numeric R>
void stratax::core::validation::require_valid_division (const L &lhs, const R &rhs)
 Rejects zero divisors and unrepresentable native signed division.
 
template<typename Value , Integral Count>
constexpr bool stratax::core::validation::valid_shift_count (const Count &count) noexcept
 Tests whether a shift count is valid for a value type.
 
template<typename Value , Integral Count>
void stratax::core::validation::require_valid_shift_count (const Count &count)
 Rejects shift counts outside the stored value type's bit width.
 

Detailed Description

Shared validation for division operands and integral shift counts.

Definition in file NumericValidation.hpp.

Function Documentation

◆ require_valid_division()

template<Numeric L, Numeric R>
void stratax::core::validation::require_valid_division ( const L &  lhs,
const R &  rhs 
)

Rejects zero divisors and unrepresentable native signed division.

Integral checks use the type of the native lhs / rhs expression, after integer promotion and usual arithmetic conversions. Result-container dtype promotion occurs later and does not change whether that expression is valid. A narrow signed minimum divided by minus one can therefore be valid when the expression evaluates in a wider signed type.

Template Parameters
LNumeric left operand type.
RNumeric right operand type.
Parameters
lhsOriginal left element or scalar, before result dtype conversion.
rhsOriginal right element or scalar, before result dtype conversion.
Exceptions
Exceptions::ZeroDivisionErrorIf rhs equals zero, including floating-point signed zero or complex zero.
Exceptions::OverflowErrorIf integral division would evaluate the native signed expression type's minimum value divided by minus one.
Note
This does not check narrowing to a result dtype or floating-point overflow.
Complexity
O(1).

Definition at line 38 of file NumericValidation.hpp.

◆ require_valid_shift_count()

template<typename Value , Integral Count>
void stratax::core::validation::require_valid_shift_count ( const Count &  count)

Rejects shift counts outside the stored value type's bit width.

Invariant
A successful return guarantees that count is valid for Value.
Exceptions
Exceptions::ValueErrorIf count is negative or is not smaller than the bit width of Value.
Complexity
O(1).

Definition at line 97 of file NumericValidation.hpp.

◆ valid_shift_count()

template<typename Value , Integral Count>
constexpr bool stratax::core::validation::valid_shift_count ( const Count &  count)
constexprnoexcept

Tests whether a shift count is valid for a value type.

Template Parameters
ValueType of the value being shifted.
CountIntegral shift-count type.
Parameters
countShift count to validate.
Returns
true when count is non-negative and smaller than the bit width of Value; otherwise false.
Invariant
The shift count is never modified.
Complexity
O(1).

Definition at line 72 of file NumericValidation.hpp.