<cstdlib>

From the <cstdlib> header we support functions and structures that are analogous to std::div. These are of particular importance with this library since unlike a hardware type, the compiler may not be able to optimize a division followed by a modulo operation. Knuth’s algorithm naturally returns both so it costs nearly nothing above a division or modulo to get both results.

#include <boost/int128/cstdlib.hpp>

Structures

namespace boost {
namespace int128 {

struct u128div_t
{
    uint128_t quot;
    uint128_t rem;
};

struct i128div_t
{
    int128_t quot;
    int128_t rem;
};

} // namespace int128
} // namespace boost

div

Using the structures defined above, the div function computes both quotient and remainder simultaneously:

namespace boost {
namespace int128 {

constexpr u128div_t div(uint128_t lhs, uint128_t rhs) noexcept;

constexpr i128div_t div(int128_t lhs, int128_t rhs) noexcept;

} // namespace int128
} // namespace boost

The result of quot and rem from this function, including the sign, are the same as if you performed division and modulo separately.