DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

ldiv(S-osr5)


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-osr5)

Standards conformance

ldiv is conformant with:

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


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005