copysign, copysignf, copysignl
From cppreference.com
| Defined in header <math.h>
|
||
| float copysignf( float x, float y ); |
(1) | (since C99) |
| double copysign( double x, double y ); |
(2) | (since C99) |
| long double copysignl( long double x, long double y ); |
(3) | (since C99) |
| Defined in header <tgmath.h>
|
||
| #define copysign(from, to) |
(7) | (since C99) |
1-3) Composes a floating point value with the magnitude of
x and the sign of y. 4) Type-generic macro: If any argument has type long double,
copysignl is called. Otherwise, if any argument has integer type or has type double, copysign is called. Otherwise, copysignf is called.Parameters
| x, y | - | floating point values |
Return value
If no errors occur, the floating point value with the magnitude of x and the sign of y is returned.
If x is NaN, then NaN with the sign of y is returned.
If y is -0, the result is only negative if the implementation supports the signed zero consistently in arithmetic operations.
Error handling
This function is not subject to any errors specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- The returned value is exact (FE_INEXACT is never raised) and independent of the current rounding mode.
Notes
copysign is the only portable way to manipulate the sign of a NaN value (to examine the sign of a NaN, signbit may also be used).