SAMEQUANTUM 3CW "08 February 2007" "mathcw-1.00"

Table of contents


NAME

samequantum, samequantumd, samequantumdf, samequantumdl, samequantumdll, samequantumf, samequantuml, samequantumll - determine whether two floating-point values have the same exponent

SYNOPSIS

extern int samequantumf (float x, float y);

extern int samequantum (double x, double y);

extern int samequantuml (long double x, long double y);

extern int samequantumll (long_long_double x, long_long_double y);

extern int samequantumw (__float80 x, __float80 y);

extern int samequantumq (__float128 x, __float128 y);

extern int samequantumdf (decimal_float x, decimal_float y);

extern int samequantumd (decimal_double x, decimal_double y);

extern int samequantumdl (decimal_long_double x, decimal_long_double y);

extern int samequantumdll (decimal_long_long_double x, decimal_long_long_double y);

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


DESCRIPTION

samequantum(x,y) determines whether the arguments have the same decimal exponent.

This function is particularly useful for doing fixed-point arithmetic with decimal floating-point arithmetic, since it provides a way to check that the computations have not unexpectedly altered the scale.


RETURN VALUES

Return 1 if the arguments have the same decimal exponent, or are both Infinity, or both NaN. Otherwise, return 0.

ERRORS

None. The functions always succeed.

EXAMPLES

Here are some examples of how the samequantum(x,y) function works in decimal and binary arithmetic:
decimal samequantumd(+1.00DD, +9.99DD) -> 1 samequantumd(+1.00DD, +9999.99DD) -> 1 samequantumd(+1DD, +1.00DD) -> 0 samequantumd(+100DD, +1.00DD) -> 0 samequantumd(+NaN(0x1234), +1.00DD) -> 0 samequantumd(+100DD, +NaN(0x1234)) -> 0 samequantumd(+NaN(0x1234), +NaN(0x5678)) -> 1 samequantumd(+Infinity, -Infinity) -> 1 samequantumd(-Infinity, +Infinity) -> 1 samequantumd(+100.00DD, -Infinity) -> 0 samequantumd(-Infinity, +100.00DD) -> 0
binary samequantum(+1, +1.9375) -> 1 samequantum(+1, +9999.75) -> 0 samequantum(+1, +1) -> 1 samequantum(+100, +1) -> 0 samequantum(NaN, +1) -> 0 samequantum(+100, NaN) -> 0 samequantum(NaN, NaN) -> 1 samequantum(+Infinity, -Infinity) -> 1 samequantum(-Infinity, +Infinity) -> 1 samequantum(+100, -Infinity) -> 0 samequantum(-Infinity, +100) -> 0

The parenthesized hexadecimal values following some of the NaNs are payloads stored in the significand bits.


SEE ALSO

normalize(3CW), quantize(3CW).