mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-07 10:47:05 +00:00
25 lines
500 B
C++
25 lines
500 B
C++
#include <xrpl/basics/mulDiv.h>
|
|
|
|
#include <boost/multiprecision/cpp_int.hpp> // IWYU pragma: keep
|
|
|
|
#include <cstdint>
|
|
#include <optional>
|
|
|
|
namespace xrpl {
|
|
|
|
std::optional<std::uint64_t>
|
|
mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
|
|
{
|
|
boost::multiprecision::uint128_t result;
|
|
result = multiply(result, value, mul);
|
|
|
|
result /= div;
|
|
|
|
if (result > xrpl::muldiv_max)
|
|
return std::nullopt;
|
|
|
|
return static_cast<std::uint64_t>(result);
|
|
}
|
|
|
|
} // namespace xrpl
|