archonitelabs / radiant-cpp

Radiant Library (C++)
Apache License 2.0
2 stars 2 forks source link

Numerics implementation #6

Open jxy-s opened 5 months ago

jxy-s commented 5 months ago

Description of the feature, modification, idea, or suggestion.

It is a common pattern to want to fail cleanly if some numeric boundary condition is met. As an example, Microsoft provides intsafe.h and ntintsafe.h functions. In a similar vein, Radiant should provide objects that aid in this and lean toward encouraging/providing safe constructs.

Proposed implementation details (optional)

Rust has a good story and semantics around their numeric handling (e.g. u8, u32, etc.). The Rust APIs here give checked, unchecked, and saturating APIs that seem reasonable. We should consider borrowing from their semantics.

jxy-s commented 5 months ago

This was partially implemented for up to 32 bit wide integers. More compiler-specific support is necessary to support optimizing 64 bit integers. The initial work provides a limited set of operations against the integers - such as saturating and checked addition, subtraction, and multiplication.