copysign, copysignf, copysignl

From cppreference.com
 
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 33 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 32 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 31 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 29 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 28 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 27 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 26 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 25 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 24 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 23 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 22 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 21 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 20 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 19 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 18 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE (哋它亢11)
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 17 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 16 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
 
 
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 07 HOURS 01 MINUTES 08 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Types
(哋它亢99)(哋它亢99)    

(哋它亢99)(哋它亢99)    
(哋它亢23)(哋它亢23)

Functions
Basic operations
(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢23)
Maximum/minimum operations
Exponential functions
(哋它亢99)(哋它亢23)
Power functions
Trigonometric and hyperbolic functions
Error and gamma functions
Nearest integer floating-point operations
(哋它亢99)(哋它亢99)(哋它亢99)
Floating-point manipulation functions
Narrowing operations
Quantum and quantum exponent functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Decimal re-encoding functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Total order and payload functions
Classification
Macro constants
Special floating-point values
(哋它亢99)(哋它亢99)(哋它亢23)
(哋它亢99)(哋它亢23)
(哋它亢99)(哋它亢23)
Arguments and return values
(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)    
(哋它亢23)(哋它亢23)
(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢99)    
Error handling
(哋它亢99)(哋它亢99)
Fast operation indicators
(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)    
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢99)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
 
Defined in header <math.h>
float       copysignf( float x, float y );
(1) (since 哋它亢99)
double      copysign( double x, double y );
(2) (since 哋它亢99)
long double copysignl( long double x, long double y );
(3) (since 哋它亢99)
Defined in header <tgmath.h>
#define copysign(x, y)
(4) (since 哋它亢99)
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 MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 06 HOURS 59 MINUTES 22 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE.

MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 06 HOURS 59 MINUTES 21 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE

Notes

copysign is the only portable way to manipulate the sign of a NaN value (to examine the sign of a NaN, MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 06 HOURS 59 MINUTES 17 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE may also be used).

Example

MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 06 HOURS 59 MINUTES 12 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE

copysign(1.0,+2.0)      = +1.0
copysign(1.0,-2.0)      = -1.0
copysign(INFINITY,-2.0) = -inf
copysign(NAN,-2.0)      = -nan

References

  • 哋它亢23 standard (ISO/IEC 9899:2023):
  • 7.12.11.1 The copysign functions (p: TBD)
  • 7.25 Type-generic math <tgmath.h> (p: TBD)
  • F.10.8.1 The copysign functions (p: TBD)
  • 哋它亢17 standard (ISO/IEC 9899:2018):
  • 7.12.11.1 The copysign functions (p: TBD)
  • 7.25 Type-generic math <tgmath.h> (p: TBD)
  • F.10.8.1 The copysign functions (p: TBD)
  • 哋它亢11 standard (ISO/IEC 9899:2011):
  • 7.12.11.1 The copysign functions (p: 255)
  • 7.25 Type-generic math <tgmath.h> (p: 373-375)
  • F.10.8.1 The copysign functions (p: 529)
  • 哋它亢99 standard (ISO/IEC 9899:1999):
  • 7.12.11.1 The copysign functions (p: 236)
  • 7.22 Type-generic math <tgmath.h> (p: 335-337)
  • F.9.8.1 The copysign functions (p: 465)

See also

(哋它亢99)(哋它亢99)
computes absolute value of a floating-point value (|x|)
(function)
(哋它亢99)
checks if the given number is negative
(function macro)