GNU Info

Info Node: (libc.info)FP Bit Twiddling

(libc.info)FP Bit Twiddling


Next: FP Comparison Functions Prev: Remainder Functions Up: Arithmetic Functions
Enter node , (file) or (file)node

Setting and modifying single bits of FP values
----------------------------------------------

   There are some operations that are too complicated or expensive to
perform by hand on floating-point numbers.  ISO C99 defines functions
to do these operations, which mostly involve changing single bits.

 - Function: double copysign (double X, double Y)
 - Function: float copysignf (float X, float Y)
 - Function: long double copysignl (long double X, long double Y)
     These functions return X but with the sign of Y.  They work even
     if X or Y are NaN or zero.  Both of these can carry a sign
     (although not all implementations support it) and this is one of
     the few operations that can tell the difference.

     `copysign' never raises an exception.

     This function is defined in IEC 559 (and the appendix with
     recommended functions in IEEE 754/IEEE 854).

 - Function: int signbit (_float-type_ X)
     `signbit' is a generic macro which can work on all floating-point
     types.  It returns a nonzero value if the value of X has its sign
     bit set.

     This is not the same as `x < 0.0', because IEEE 754 floating point
     allows zero to be signed.  The comparison `-0.0 < 0.0' is false,
     but `signbit (-0.0)' will return a nonzero value.

 - Function: double nextafter (double X, double Y)
 - Function: float nextafterf (float X, float Y)
 - Function: long double nextafterl (long double X, long double Y)
     The `nextafter' function returns the next representable neighbor of
     X in the direction towards Y.  The size of the step between X and
     the result depends on the type of the result.  If X = Y the
     function simply returns Y.  If either value is `NaN', `NaN' is
     returned.  Otherwise a value corresponding to the value of the
     least significant bit in the mantissa is added or subtracted,
     depending on the direction.  `nextafter' will signal overflow or
     underflow if the result goes outside of the range of normalized
     numbers.

     This function is defined in IEC 559 (and the appendix with
     recommended functions in IEEE 754/IEEE 854).

 - Function: double nexttoward (double X, long double Y)
 - Function: float nexttowardf (float X, long double Y)
 - Function: long double nexttowardl (long double X, long double Y)
     These functions are identical to the corresponding versions of
     `nextafter' except that their second argument is a `long double'.

 - Function: double nan (const char *TAGP)
 - Function: float nanf (const char *TAGP)
 - Function: long double nanl (const char *TAGP)
     The `nan' function returns a representation of NaN, provided that
     NaN is supported by the target platform.  `nan
     ("N-CHAR-SEQUENCE")' is equivalent to `strtod
     ("NAN(N-CHAR-SEQUENCE)")'.

     The argument TAGP is used in an unspecified manner.  On IEEE 754
     systems, there are many representations of NaN, and TAGP selects
     one.  On other systems it may do nothing.


automatically generated by info2www version 1.2.2.9