aboutsummaryrefslogtreecommitdiffstats
path: root/native/include/math-helper.h
blob: 850e3a5b0becc128f091616bcf7a5eb22ca19f97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef MATH_HELPER_H
#define MATH_HELPER_H

#include "time-types.h"

static inline unsigned long divide_with_ceil(unsigned long numer,
					     unsigned long denom)
{
	if (numer % denom == 0)
		return numer / denom;
	else
		/* integer division computes implicit floor */
		return (numer / denom) + 1;
}




static inline integral_t divide_with_ceil(const integral_t &numer,
					  const integral_t &denom)
{
	integral_t result;
	mpz_cdiv_q(result.get_mpz_t(), numer.get_mpz_t(), denom.get_mpz_t());
	return result;
}


static inline integral_t round_up(const fractional_t &f)
{
	integral_t result;
	mpz_cdiv_q(result.get_mpz_t(), f.get_num_mpz_t(), f.get_den_mpz_t());
	return result * f.get_den();
}


#endif