[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


abs, div, labs, ldiv, imul_dbl, umul_dbl, llabs, or lldiv Subroutine

Purpose

Computes absolute value, division, and double precision multiplication of integers.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>

int abs ( i  )
int i;

#include <stdlib.h>

long labs ( i )
long i;

#include <stdlib.h>


div_t div ( Numerator, Denominator)
int Numerator: Denominator;

#include <stdlib.h>


void imul_dbl ( i, j, Result)
long i, j;
long *Result;

#include <stdlib.h>

ldiv_t ldiv (Numerator, Denominator)
long Numerator: Denominator;

#include <stdlib.h>

void umul_dbl (i, j, Result)
unsigned long i, j;
unsigned long *Result;

#include <stdlib.h>

long long int llabs(i)
long long int i;

#include <stdlib.h>

lldiv_t lldiv (Numerator, Denominator)
long long int Numerator, Denominator;

Description

The abs subroutine returns the absolute value of its integer operand.

Note: A twos-complement integer can hold a negative number whose absolute value is too large for the integer to hold. When given this largest negative value, the abs subroutine returns the same value.

The div subroutine computes the quotient and remainder of the division of the number represented by the Numerator parameter by that specified by the Denominator parameter. 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 cannot be represented (for example, if the denominator is 0), the behavior is undefined.

The labs and ldiv subroutines are included for compatibility with the ANSI C library, and accept long integers as parameters, rather than as integers.

The imul_dbl subroutine computes the product of two signed longs, i and j, and stores the double long product into an array of two signed longs pointed to by the Result parameter.

The umul_dbl subroutine computes the product of two unsigned longs, i and j, and stores the double unsigned long product into an array of two unsigned longs pointed to by the Result parameter.

The llabs and lldiv subroutines compute the absolute value and division of long long integers. These subroutines operate under the same restrictions as the abs and div subroutines.

Note: When given the largest negative value, the llabs subroutine (like the abs subroutine) returns the same value.

Parameters


i Specifies, for the abs subroutine, some integer; for labs and imul_dbl, some long integer; for the umul_dbl subroutine, some unsigned long integer; for the llabs subroutine, some long long integer.
Numerator Specifies, for the div subroutine, some integer; for the ldiv subroutine, some long integer; for lldiv, some long long integer.
j Specifies, for the imul_dbl subroutine, some long integer; for the umul_dbl subroutine, some unsigned long integer.
Denominator Specifies, for the div subroutine, some integer; for the ldiv subroutine, some long integer; for lldiv, some long long integer.
Result Specifies, for the imul_dbl subroutine, some long integer; for the umul_dbl subroutine, some unsigned long integer.

Return Values

The abs, labs, and llabs subroutines return the absolute value. The imul_dbl and umul_dbl subroutines have no return values. The div subroutine returns a structure of type div_t. The ldiv subroutine returns a structure of type ldiv_t, comprising the quotient and the remainder. The structure is displayed as:

struct ldiv_t {
  int quot; /* quotient */
  int rem;  /* remainder */
};

The lldiv subroutine returns a structure of type lldiv_t, comprising the quotient and the remainder.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]