leapc
Loading...
Searching...
No Matches
Data Structures | Functions
quo_mod.h File Reference

Quotient and modulus prototypes. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  quo_mod
 Quotient and remainder in integer space. More...
 

Functions

struct quo_mod quo_mod (int x, int y)
 Compute the integer quotient and modulus.
 

Detailed Description

Quotient and modulus prototypes.

Header file for quotient and modulus function implementations.

Definition in file quo_mod.h.

Function Documentation

◆ quo_mod()

struct quo_mod quo_mod ( int  x,
int  y 
)

Compute the integer quotient and modulus.

Performs an integer modulo operation. Then subtracts the modulus from the numerator and applies an integer division in order to compute the quotient.

The following invariant proves true: the numerator matches the denominator multiplied by the quotient plus the modulus.

struct quo_mod qm = quo_mod(x, y);
x == (y * qm.quo + qm.mod);
Quotient and remainder in integer space.
Definition quo_mod.h:22
int mod
Integer modulus.
Definition quo_mod.h:30
int quo
Integer quotient.
Definition quo_mod.h:26
Parameters
xNumerator integer.
yDenominator integer. Must not be zero.
Returns
quo_mod structure comprising the quotient and modulus.
Remarks
Like Lua's modulo operator, this function ensures that the modulus is always non-negative when the denominator is positive, and always non-positive when the denominator is negative.
Note
The quo_mod identifier exists in structure namespace as well as function namespace.
Warning
Throws a division-by-zero error if the denominator y is zero.

Definition at line 12 of file quo_mod.c.