From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Fmath%2Fcopysign.html | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 devdocs/c/numeric%2Fmath%2Fcopysign.html (limited to 'devdocs/c/numeric%2Fmath%2Fcopysign.html') diff --git a/devdocs/c/numeric%2Fmath%2Fcopysign.html b/devdocs/c/numeric%2Fmath%2Fcopysign.html new file mode 100644 index 00000000..3e67f811 --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fcopysign.html @@ -0,0 +1,51 @@ +

copysign, copysignf, copysignl

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(x, y)
+
(4) (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),

+

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).

+

Example

#include <stdio.h>
+#include <math.h>
+ 
+int main(void)
+{
+    printf("copysign(1.0,+2.0)      = %+.1f\n", copysign(1.0,+2.0));
+    printf("copysign(1.0,-2.0)      = %+.1f\n", copysign(1.0,-2.0));
+    printf("copysign(INFINITY,-2.0) = %f\n",    copysign(INFINITY,-2.0));
+    printf("copysign(NAN,-2.0)      = %f\n",    copysign(NAN,-2.0));
+}

Possible output:

+
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

See also

+ + +
+
(C99)(C99)
computes absolute value of a floating-point value (\(\small{|x|}\)|x|)
(function)
+
(C99)
checks if the given number is negative
(function macro)
C++ documentation for copysign
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/math/copysign +

+
-- cgit v1.2.3