Next: Rounding Functions, Previous: Absolute Value, Up: Arithmetic Functions

The functions described in this section are primarily provided as a way to efficiently perform certain low-level manipulations on floating point numbers that are represented internally using a binary radix; see Floating Point Concepts. These functions are required to have equivalent behavior even if the representation does not use a radix of 2, but of course they are unlikely to be particularly efficient in those cases.

All these functions are declared in `math.h`.

— Function: double **frexp** (`double value, int *exponent`)

— Function: floatfrexpf(float value, int *exponent)

— Function: long doublefrexpl(long double value, int *exponent)

These functions are used to split the number

valueinto a normalized fraction and an exponent.If the argument

valueis not zero, the return value isvaluetimes a power of two, and is always in the range 1/2 (inclusive) to 1 (exclusive). The corresponding exponent is stored in`*`

exponent; the return value multiplied by 2 raised to this exponent equals the original numbervalue.For example,

`frexp (12.8, &exponent)`

returns`0.8`

and stores`4`

in`exponent`

.If

valueis zero, then the return value is zero and zero is stored in`*`

exponent.

— Function: double **ldexp** (`double value, int exponent`)

— Function: floatldexpf(float value, int exponent)

— Function: long doubleldexpl(long double value, int exponent)

These functions return the result of multiplying the floating-point number

valueby 2 raised to the powerexponent. (It can be used to reassemble floating-point numbers that were taken apart by`frexp`

.)For example,

`ldexp (0.8, 4)`

returns`12.8`

.

The following functions, which come from BSD, provide facilities
equivalent to those of `ldexp`

and `frexp`

. See also the
ISO C function `logb`

which originally also appeared in BSD.

— Function: double **scalb** (`double value, int exponent`)

— Function: floatscalbf(float value, int exponent)

— Function: long doublescalbl(long double value, int exponent)

The

`scalb`

function is the BSD name for`ldexp`

.

— Function: long long int **scalbn** (`double x, int n`)

— Function: long long intscalbnf(float x, int n)

— Function: long long intscalbnl(long double x, int n)

`scalbn`

is identical to`scalb`

, except that the exponentnis an`int`

instead of a floating-point number.

— Function: long long int **scalbln** (`double x, long int n`)

— Function: long long intscalblnf(float x, long int n)

— Function: long long intscalblnl(long double x, long int n)

`scalbln`

is identical to`scalb`

, except that the exponentnis a`long int`

instead of a floating-point number.

— Function: long long int **significand** (`double x`)

— Function: long long intsignificandf(float x)

— Function: long long intsignificandl(long double x)

`significand`

returns the mantissa ofxscaled to the range [1, 2). It is equivalent to`scalb (`

x`, (double) -ilogb (`

x`))`

.This function exists mainly for use in certain standardized tests of IEEE 754 conformance.