| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH copysign 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
copysign, copysignf, copysignl \- copy sign of a number |
| 10 |
.SH LIBRARY |
| 11 |
Math library |
| 12 |
.RI ( libm ,\~ \-lm ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <math.h> |
| 16 |
.P |
| 17 |
.BI "double copysign(double " x ", double " y ); |
| 18 |
.BI "float copysignf(float " x ", float " y ); |
| 19 |
.BI "long double copysignl(long double " x ", long double " y ); |
| 20 |
.fi |
| 21 |
.P |
| 22 |
.RS -4 |
| 23 |
Feature Test Macro Requirements for glibc (see |
| 24 |
.BR feature_test_macros (7)): |
| 25 |
.RE |
| 26 |
.P |
| 27 |
.BR copysign (), |
| 28 |
.BR copysignf (), |
| 29 |
.BR copysignl (): |
| 30 |
.nf |
| 31 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 32 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 33 |
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
| 34 |
.fi |
| 35 |
.SH DESCRIPTION |
| 36 |
These functions return a value whose absolute value matches that of |
| 37 |
.IR x , |
| 38 |
but whose sign bit matches that of |
| 39 |
.IR y . |
| 40 |
.P |
| 41 |
For example, |
| 42 |
.I "copysign(42.0,\ \-1.0)" |
| 43 |
and |
| 44 |
.I "copysign(\-42.0, \-1.0)" |
| 45 |
both return \-42.0. |
| 46 |
.SH RETURN VALUE |
| 47 |
On success, these functions return a value whose magnitude is taken from |
| 48 |
.I x |
| 49 |
and whose sign is taken from |
| 50 |
.IR y . |
| 51 |
.P |
| 52 |
If |
| 53 |
.I x |
| 54 |
is a NaN, |
| 55 |
a NaN with the sign bit of |
| 56 |
.I y |
| 57 |
is returned. |
| 58 |
.SH ERRORS |
| 59 |
No errors occur. |
| 60 |
.SH ATTRIBUTES |
| 61 |
For an explanation of the terms used in this section, see |
| 62 |
.BR attributes (7). |
| 63 |
.TS |
| 64 |
allbox; |
| 65 |
lbx lb lb |
| 66 |
l l l. |
| 67 |
Interface Attribute Value |
| 68 |
T{ |
| 69 |
.na |
| 70 |
.nh |
| 71 |
.BR copysign (), |
| 72 |
.BR copysignf (), |
| 73 |
.BR copysignl () |
| 74 |
T} Thread safety MT-Safe |
| 75 |
.TE |
| 76 |
.SH VERSIONS |
| 77 |
On architectures where the floating-point formats are not IEEE 754 compliant, |
| 78 |
these functions may treat a negative zero as positive. |
| 79 |
.SH STANDARDS |
| 80 |
C11, POSIX.1-2008. |
| 81 |
.P |
| 82 |
This function is defined in IEC 559 (and the appendix with |
| 83 |
recommended functions in IEEE 754/IEEE 854). |
| 84 |
.SH HISTORY |
| 85 |
C99, POSIX.1-2001, 4.3BSD. |
| 86 |
.SH SEE ALSO |
| 87 |
.BR signbit (3) |