Integer math related to multiplication, division, and rounding.
More...
#include "lib/intmath/muldiv.h"
#include "lib/err/torerr.h"
#include <stdlib.h>
Go to the source code of this file.
Integer math related to multiplication, division, and rounding.
Definition in file muldiv.c.
◆ gcd64()
static uint64_t gcd64 |
( |
uint64_t |
a, |
|
|
uint64_t |
b |
|
) |
| |
|
static |
◆ round_to_next_multiple_of()
unsigned round_to_next_multiple_of |
( |
unsigned |
number, |
|
|
unsigned |
divisor |
|
) |
| |
Return the lowest x such that x is at least number, and x modulo divisor == 0. If no such x can be expressed as an unsigned, return UINT_MAX. Asserts if divisor is zero.
Definition at line 21 of file muldiv.c.
◆ round_uint32_to_next_multiple_of()
uint32_t round_uint32_to_next_multiple_of |
( |
uint32_t |
number, |
|
|
uint32_t |
divisor |
|
) |
| |
Return the lowest x such that x is at least number, and x modulo divisor == 0. If no such x can be expressed as a uint32_t, return UINT32_MAX. Asserts if divisor is zero.
Definition at line 35 of file muldiv.c.
◆ round_uint64_to_next_multiple_of()
uint64_t round_uint64_to_next_multiple_of |
( |
uint64_t |
number, |
|
|
uint64_t |
divisor |
|
) |
| |
Return the lowest x such that x is at least number, and x modulo divisor == 0. If no such x can be expressed as a uint64_t, return UINT64_MAX. Asserts if divisor is zero.
Definition at line 50 of file muldiv.c.
◆ simplify_fraction64()
void simplify_fraction64 |
( |
uint64_t * |
numer, |
|
|
uint64_t * |
denom |
|
) |
| |
◆ tor_mul_u64_nowrap()
uint64_t tor_mul_u64_nowrap |
( |
uint64_t |
a, |
|
|
uint64_t |
b |
|
) |
| |
Return the unsigned integer product of a and b. If overflow is detected, return UINT64_MAX instead.
Definition at line 75 of file muldiv.c.