styyx-util 1.0
Utility Header for SKSE Plugin development
Loading...
Searching...
No Matches
StyyxUtil::MathUtil Struct Reference

#include <st-math.h>

Static Public Member Functions

template<typename T>
static T SafelyAdd (T base, T increment)
 Template function to add to a value without ever risking overflowing the maximum value that type can have.
template<typename T>
static T SafelyAddWithCap (T base, T increment, T cap=std::numeric_limits< T >::max())
 Add a value to another one and cap the result.

Member Function Documentation

◆ SafelyAdd()

template<typename T>
T StyyxUtil::MathUtil::SafelyAdd ( T base,
T increment )
inlinestatic

Template function to add to a value without ever risking overflowing the maximum value that type can have.

Template Parameters
THas to be a number
Parameters
baseThe value to add to
incrementThe value added to base
Returns
The result of the addition
Example
const uint8_t result = MathUtil::SafelyAdd<uint8_t>(200, 100);
// result will be 255 instead of overflowing
static T SafelyAdd(T base, T increment)
Template function to add to a value without ever risking overflowing the maximum value that type can ...
Definition st-math.h:25
Deprecated
Use MathUtil::SafelyAddWithCap instead. You can use it without passing a cap to cap it to numeric limits

◆ SafelyAddWithCap()

template<typename T>
T StyyxUtil::MathUtil::SafelyAddWithCap ( T base,
T increment,
T cap = std::numeric_limits<T>::max() )
inlinestatic

Add a value to another one and cap the result.

Template Parameters
THas to be a number
Parameters
baseThe value to add to
incrementThe value added to base
capA cap for the result. If nothing is passed, the cap will be the numeric limit
Returns
the result of the addition
Note
If cap is less than base, the result will be capped to cap regardless of increment

The documentation for this struct was generated from the following file: