Integer Utilities
Description
The library provides utility functions for safe integer types.
These operate on the non-bounded unsigned types (u8, u16, u32, u64, u128) and their verified counterparts.
#include <boost/safe_numbers/integer_utilities.hpp>
isqrt
Runtime Overload
template <non_bounded_unsigned_library_type T>
requires (!is_verified_type_v<T>)
constexpr auto isqrt(const T val) -> T;
Returns the integer square root of val, i.e., the largest integer r such that r * r <= val.
Uses Newton’s method on the underlying hardware type. The computation cannot overflow and converges rapidly.
Verified Overload
template <non_bounded_unsigned_library_type T>
consteval auto isqrt(const verified_type_basis<T> val) -> verified_type_basis<T>;
Compile-time only overload for verified types. Delegates to the runtime overload after extracting the basis value, and wraps the result back into a verified type.
Since isqrt is consteval for verified types, the result is guaranteed to be a compile-time constant.