Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ldiv - Division with integers (long int)

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

ldiv_t ldiv(long int dividend, long int divisor);

ldiv calculates the quotient and the remainder of the division of dividend by divisor.
Both the arguments and the result are of type long int.

The sign of the quotient is the same as the sign of the algebraic quotient. The value of the quotient is the highest integer less than or equal to the absolute value of the algebraic quotient.

The remainder is expressed by the following equation:

Quotient * Divisor + Remainder = Dividend

Return val.

Structure of type ldiv_t

containing both the quotient quot and the remainder rem as integer values.

Example

ldiv_t d;
d = ldiv( 7, 3);        /*  d.quot =  2,  d.rem =  1  */
d = ldiv(-7, 3);        /*  d.quot = -2,  d.rem = -1  */
d = ldiv( 7,-3);        /*  d.quot = -2,  d.rem =  1  */
d = ldiv(-7,-3);        /*  d.quot =  2,  d.rem = -1  */

See also

div, lldiv