NORMALIZE 3CW "09 February 2007" "mathcw-1.00"

Table of contents


NAME

normalize, normalized, normalizedf, normalizedl, normalizedll, normalizef, normalizel, normalizell - trim trailing zeros from floating-point number

SYNOPSIS

extern float normalizef (float x);

extern double normalize (double x);

extern long double normalizel (long double x);

extern long_long_double normalizell (long_long_double x);

extern __float80 normalizew (__float80 x);

extern __float128 normalizeq (__float128 x);

extern decimal_float normalizedf (decimal_float x);

extern decimal_double normalized (decimal_double x);

extern decimal_long_double normalizedl (decimal_long_double x);

extern decimal_long_long_double normalizedll (decimal_long_long_double x);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

normalize(x) trims trailing fractional zero digits from a copy of x and returns the value of the copy.

Decimal floating-point arithmetic has integer significands, so a number may have multiple representations of equal numerical value that differ in the number of trailing zeros and exponent.


RETURN VALUES

Return the copy of x with trailing fractional zeros removed. If the argument is Infinity or NaN, return the argument.

For binary floating-point arithmetic on modern systems, numbers are always normalized, so return the argument unchanged.


ERRORS

None. The functions always succeed.

EXAMPLES

Here are some examples of how the normalize(x,y) function works in decimal arithmetic:
normalized(+0.00100DD) -> +0.001DD normalized(+1.00DD) -> +1DD normalized(+100DD) -> +1E+2DD normalized(+100.00DD) -> +1E+2DD normalized(+NaN(0x1234)) -> +NaN(0x1234) normalized(+NaN(0x1234)) -> +NaN(0x1234) normalized(+Infinity) -> +Infinity normalized(-Infinity) -> -Infinity

The parenthesized hexadecimal values following some of the NaNs are payloads stored in the significand bits to identify the NaN that is returned.

The peculiar result for the second binary example arises because 100 = 1.5625 * 2**6.


SEE ALSO

quantize(3CW), samequantum(3CW).