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: float copysignf (float x, float y)
— Function: long double copysignl (long double x, long double y)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
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.
copysignnever raises an exception.This function is defined in IEC 559 (and the appendix with recommended functions in IEEE 754/IEEE 854).
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
signbitis 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.0is false, butsignbit (-0.0)will return a nonzero value.
— Function: float nextafterf (float x, float y)
— Function: long double nextafterl (long double x, long double y)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The
nextafterfunction 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 isNaN,NaNis returned. Otherwise a value corresponding to the value of the least significant bit in the mantissa is added or subtracted, depending on the direction.nextafterwill 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: float nexttowardf (float x, long double y)
— Function: long double nexttowardl (long double x, long double y)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions are identical to the corresponding versions of
nextafterexcept that their second argument is along double.
— Function: float nextupf (float x)
— Function: long double nextupl (long double x)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The
nextupfunction returns the next representable neighbor of x in the direction of positive infinity. If x is the smallest negative subnormal number in the type of x the function returns-0. If x =0the function returns the smallest positive subnormal number in the type of x. If x is NaN, NaN is returned. If x is +∞, +∞ is returned.nextupis based on TS 18661 and currently enabled as a GNU extension.nextupnever raises an exception except for signaling NaNs.
— Function: float nextdownf (float x)
— Function: long double nextdownl (long double x)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The
nextdownfunction returns the next representable neighbor of x in the direction of negative infinity. If x is the smallest positive subnormal number in the type of x the function returns+0. If x =0the function returns the smallest negative subnormal number in the type of x. If x is NaN, NaN is returned. If x is -∞, -∞ is returned.nextdownis based on TS 18661 and currently enabled as a GNU extension.nextdownnever raises an exception except for signaling NaNs.
— Function: float nanf (const char *tagp)
— Function: long double nanl (const char *tagp)
Preliminary: | MT-Safe locale | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The
nanfunction returns a representation of NaN, provided that NaN is supported by the target platform.nan ("n-char-sequence")is equivalent tostrtod ("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.