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

Technical Reference: Base Operating System and Extensions, Volume 1


copysign, nextafter, scalb, logb, or ilogb Subroutine

Purpose

Computes certain binary floating-point arithmetic functions.

Libraries

IEEE Math Library (libm.a)
or System V Math Library (libmsaa.a)

Syntax

#include <math.h>
#include <float.h>


double copysign ( x, y)
double x, y;

double nextafter (x, y)
double x, y;

double scalb(x, y)
double x, y;

double logb(x)
double x;

int ilogb (x)
double x;

Description

These subroutines compute certain functions recommended in the IEEE Standard for Binary Floating-Point Arithmetic. The other such recommended function is provided in the class subroutine.

The copysign subroutine returns the x parameter with the same sign as the y parameter.

The nextafter subroutine returns the next representable neighbor of the x parameter in the direction of the y parameter. If x equals y, the result is the x parameter.

The scalb subroutine returns the value of the x parameter times 2 to the power of the y parameter.

The logb subroutine returns a floating-point double that is equal to the unbiased exponent of the x parameter. Special cases are:

logb (NaN) = NaNQ
logb (infinity) = +INF
logb (0) = -INF

Note: When the x parameter is finite and not zero, then the logb (x) subroutine satisfies the following equation:

1 < = scalb (|x|, -(int) logb (x)) < 2

The ilogb subroutine returns an integer that is equal to the unbiased exponent of the x parameter. Special cases are:

ilogb (NaN) = LONG_MIN
ilogb (INF) = LONG_MAX
ilogb (0) = LONG_MIN

Compile any routine that uses subroutines from the libm.a library with the -lm flag. For example: to compile the copysign.c file, enter:

cc copysign.c -lm

Parameters


x Specifies a double-precision floating-point value.
y Specifies a double-precision floating-point value.

Return Values

The nextafter subroutine sets the overflow bit in the floating-point exception status when the x parameter is finite but the nextafter (x, y) subroutine is infinite. Similarly, when the nextafter subroutine is denormalized, the underflow exception status flag is set.

The logb(0) subroutine returns an -INF value and sets the division-by-zero exception status flag.

The ilogb(0) subroutine returns a LONG_MIN value and sets the division-by-zero exception status flag.

Error Codes

If the correct value would overflow, the scalb subroutine returns +/-INF (depending on a negative or positive value of the x parameter) and sets errno to ERANGE.

If the correct value would underflow, the scalb subroutine returns a value of 0 and sets errno to ERANGE.

The logb function returns -HUGE_VAL when the x parameter is set to a value of 0 and sets errno to EDOM.

For the nextafter subroutine, if the x parameter is finite and the correct function value would overflow, HUGE_VAL is returned and errno is set to ERANGE.


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