Math helper functions. More...
Go to the source code of this file.
Functions | |
OT_WARN_UNUSED_RESULT uint64_t | udiv64_slow (uint64_t a, uint64_t b, uint64_t *rem_out) |
Computes the 64-bit quotient a / b by way of schoolbook long division. More... | |
OT_WARN_UNUSED_RESULT size_t | ceil_div (size_t a, size_t b) |
Computes ceil(a / b) in an overflow-safe way. More... | |
Math helper functions.
Definition in file math.h.
|
inline |
OT_WARN_UNUSED_RESULT uint64_t udiv64_slow | ( | uint64_t | a, |
uint64_t | b, | ||
uint64_t * | rem_out | ||
) |
Computes the 64-bit quotient a / b
by way of schoolbook long division.
This function is intentionally very slow: 64-bit divisions should not be a frequent occurence, and faster algorithms result in unreasonable code-size expenditure.
Performing division with the / operator in C code that runs on a 32-bit device can emit a polyfill like __udivdi3
; normally, this would be provided by a compiler runtime like libgcc_s, but we intentionally do not link that into on-device binaries. This function should be use to resolve link errors involving __udiv
symbols. We do not provide a libgcc-style linker alias for this function, because this operation should be explicit and not over-used.
If passed a non-null pointer, this function will also provide the remainder as a side-product.
If b == 0
, this function produces undefined behavior (in practice, a garbage result or a loop without forward progress).
a | The dividend. | |
b | The divisor. | |
[out] | rem_out | An optional out-parameter for the remainder. |