MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / get_round_direction

Function get_round_direction

extlibs/fmt/include/fmt/format-inl.h:739–753  ·  view source on GitHub ↗

Given the divisor (normally a power of 10), the remainder = v % divisor for some number v and the error, returns whether v should be rounded up, down, or whether the rounding direction can't be determined due to error. error should be less than divisor / 2.

Source from the content-addressed store, hash-verified

737// whether the rounding direction can't be determined due to error.
738// error should be less than divisor / 2.
739inline round_direction get_round_direction(uint64_t divisor, uint64_t remainder,
740 uint64_t error) {
741 FMT_ASSERT(remainder < divisor, ""); // divisor - remainder won't overflow.
742 FMT_ASSERT(error < divisor, ""); // divisor - error won't overflow.
743 FMT_ASSERT(error < divisor - error, ""); // error * 2 won't overflow.
744 // Round down if (remainder + error) * 2 <= divisor.
745 if (remainder <= divisor - remainder && error * 2 <= divisor - remainder * 2)
746 return round_direction::down;
747 // Round up if (remainder - error) * 2 >= divisor.
748 if (remainder >= error &&
749 remainder - error >= divisor - (remainder - error)) {
750 return round_direction::up;
751 }
752 return round_direction::unknown;
753}
754
755namespace digits {
756enum result {

Callers 2

on_startMethod · 0.85
on_digitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected