DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

ldiv(S)


ldiv -- divides long integers

Syntax

cc . . . -lc

#include  <stdlib.h>

struct ldiv_t { long quot; /* Quotient */ long rem; /* Remainder */ } ldiv(numerator, denominator) long numerator; long denominator;

Description

The ldiv routine divides the numerator by the denominator, computing the quotient and the remainder. The sign of the quotient is the same as that of the mathematical quotient. Its absolute value is the largest integer which is less than the absolute value of the mathematical quotient. If the denominator is zero, the program terminates with an error message.

The ldiv function is similar to the div function, the difference being that the arguments and the members of the returned structure are all of type long int.

Return value

The ldiv function returns a structure of type ldiv_t , comprising both the quotient and the remainder. The structure is defined in stdlib.h.

Example

   #include <stdlib.h>
   #include <math.h>
   

main(argc, argv) int argc; char **argv; { long int x,y; ldiv_t div_result;

x = atol(argv[1]); y = atol(argv[2]); printf("x is %ld, y is %ld\n", x, y);

div_result = ldiv(x,y); printf("The quotient is %ld, and the remainder is %ld\n", div_result.quot, div_result.rem); }

This program takes two long integers as command line arguments and displays the results of the integer division.

See also

div(S)

Standards conformance

ldiv is conformant with:

ANSI X3.159-1989 Programming Language -- C .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003