Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ div(3) — CLIX 3.1r7.6.22

Media Vault

Software Library

Restoration Projects

Artifacts Sought



  div(3)                              CLIX                              div(3)



  NAME

    div, ldiv - Computes the quotient and remainder

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <stdlib.h>

    div_t div(
      int numer ,
      int denom );

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

  PARAMETERS

    numer   Specifies the numerator of the operation.

    denom   Specifies the denominator of the operation.

  DESCRIPTION

    The div() function computes the quotient and remainder of the division of
    the numerator, numer, by the denominator, denom.  This function provides
    well-defined semantics for the signed integral division and remainder
    operations, unlike the implementation-defined semantics of the built-in
    operations.  The sign of the resulting quotient is that of the algebraic
    quotient; and, if the division is inexact, the magnitude of the resulting
    quotient is the largest integer less than the magnitude of the algebraic
    quotient.  If the result cannot be represented, the behavior is undefined;
    otherwise, quotient * denom + remainder = numer.

    The ldiv() function is similar to div(), except that the arguments and the
    members of the returned structure (which has type ldiv_t) all have type
    long int and long long, respectively.

  EXAMPLES

    In this example, the numerator is 20 and the denominator is 6.  The div()
    function computes the quotient and the remainder.  A message appears,
    describing the results.

    #include <stdlib.h>

    main()



  2/94 - Intergraph Corporation                                              1






  div(3)                              CLIX                              div(3)



    {
         int i_num = 20, i_den = 6;
         div_t i_result = div(i_num, i_den);

         printf("%d/%d = %d remainder %d0,i_num, i_den,
              i_result.quot, i_result.rem);
    }


  RETURN VALUES

    The div() function returns a structure of type div_t, comprising both the
    quotient and remainder, as shown here:

    int     quot;     /*quotient*/
    int     rem;      /*remainder*/


    The ldiv() function returns a structure of type ldiv_t, comprising both
    the quotient and remainder, as shown here:

    long int        quot;     /*quotient*/
    long int        rem;      /*remainder*/































  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026