Tor 0.4.9.1-alpha-dev
Functions
muldiv.c File Reference

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.

Functions

unsigned round_to_next_multiple_of (unsigned number, unsigned divisor)
 
uint32_t round_uint32_to_next_multiple_of (uint32_t number, uint32_t divisor)
 
uint64_t round_uint64_to_next_multiple_of (uint64_t number, uint64_t divisor)
 
static uint64_t gcd64 (uint64_t a, uint64_t b)
 
uint64_t tor_mul_u64_nowrap (uint64_t a, uint64_t b)
 
void simplify_fraction64 (uint64_t *numer, uint64_t *denom)
 

Detailed Description

Integer math related to multiplication, division, and rounding.

Definition in file muldiv.c.

Function Documentation

◆ gcd64()

static uint64_t gcd64 ( uint64_t  a,
uint64_t  b 
)
static

Definition at line 62 of file muldiv.c.

◆ 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 
)

Definition at line 89 of file muldiv.c.

◆ 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.