libcalendars
0.1.0
|
#include <math.h>
#include <stdlib.h>
Go to the source code of this file.
Functions | |
div_t | clm_pdiv (int d, int v) |
Division with Positive Ramainder. More... | |
int | clm_floor_div (int a, int b) |
Floor Division Function. More... | |
int | clm_mod (int a, int b) |
Modular Division Function. More... | |
int clm_floor_div | ( | int | a, |
int | b | ||
) |
Floor Division Function.
C implentation of integer division results in truncation toward zero. While we ofthen need floor, ceil or rounding. This function simulates floor division in an optimized way. It returns:
\[ \left\lfloor\frac{a}{b}\right\rfloor \]
int clm_mod | ( | int | x, |
int | y | ||
) |
Modular Division Function.
This function returns non-negative remainder from division of \(y\) by \(x\), i.e. \(x \bmod y\)
\[ x \bmod y=x-y\left\lfloor\frac{x}{y}\right\rfloor \]
div_t clm_pdiv | ( | int | y, |
int | x | ||
) |
Division with Positive Ramainder.
Division of a whole number \(y\) by another whole number \(x\) results in a quotient \(q\) and a remainder \(r\). In our calculations, the remainder never should be negative. Then \(0 ≤ r \lt \left|x\right|\) As a result:
\begin{eqnarray*} q &=& \left\lfloor\frac{y}{x}\right\rfloor \\ r &=& y \bmod x = y − x\left\lfloor\frac{y}{x}\right\rfloor \\ y &=& qx + r \end{eqnarray*}