HPlogo HP-UX Reference Volume 4 of 5 > d

div(3C)

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

NAME

div(), ldiv() — integer division and remainder

SYNOPSIS

#include <stdlib.h>

div_t div(int numer, int denom);

ldiv_t ldiv(long int numer, long int denom);

DESCRIPTION

div()

Computes the quotient and remainder of the division of the numerator numer by the denominator denom. If the division is inexact, the sign of the resulting quotient is that of the algebraic quotient, and the magnitude of the resulting quotient is the largest integer less than the magnitude of the algebraic quotient. If the result can be represented, the result is returned in a structure of type div_t (defined in <stdlib.h>) having members quot and rem for the quotient and remainder respectively. Both members have type int and values such that quot × denom + rem = numer. If the result cannot be represented, the behavior is undefined.

ldiv()

Similar to div(), except that the arguments each have type long int and the result is returned in a structure of type ldiv_t (defined in <stdlib.h>) having long int members quot and rem for the quotient and remainder respectively.

APPLICATION USAGE

div() and ldiv() are thread-safe and async-cancel-safe.

WARNINGS

Behavior is undefined if denom is zero.

SEE ALSO

floor(3M).

STANDARDS CONFORMANCE

div(): AES, SVID3, XPG4, ANSI C

ldiv(): AES, SVID3, XPG4, ANSI C

© Hewlett-Packard Development Company, L.P.