copysign(3)
π copysign, copysignf, copysignl β copy sign of a number π
okay bestie, gather round, because this one is from the Library Functions Manual and it's honestly one of the cutest little math functions in the whole libm friend group. she's not complicated, she's not messy, she just. copies. a sign. iconic behaviour fr fr π
β¨ NAME β¨
copysign, copysignf, copysignl β copy sign of a number π
π«Ά LIBRARY π«Ά
Math library (libm, -lm) β yeah you gotta link the math girlies in, no cap.
πΈ SYNOPSIS πΈ
#include <math.h>
double copysign(double x, double y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
π§ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
copysign(), copysignf(), copysignl():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
so basically, if you want these girlies visible, you need one of those macros defined. iykyk π
π DESCRIPTION π
These functions return a value whose absolute value matches that of x, but whose sign bit matches that of y. that's it. that's the whole job. she takes the magnitude from x and the sign from y and smashes them together like the ultimate dupe hack. π¦
For example, copysign(42.0, -1.0) and copysign(-42.0, -1.0) both return -42.0. the way that BOTH of them land on the same answer regardless of x's own signβ¦ obsessed. πβ¨
π RETURN VALUE π
On success, these functions return a value whose magnitude is taken from x and whose sign is taken from y. clean. simple. no drama. π
If x is a NaN, a NaN with the sign bit of y is returned. yep, even NaN gets the glow-up and inherits y's vibe. π
π ERRORS π
No errors occur. literally none. she's perfect and she knows it. periodt. β¨
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
- Interface:
copysign(),copysignf(),copysignl()- Attribute: Thread safety
- Value: MT-Safe
translation: you can call her from all your threads at once and she will not start anything. multithread-friendly queen. π«Ά
π VERSIONS π
On architectures where the floating-point formats are not IEEE 754 compliant, these functions may treat a negative zero as positive. so, like, heads up on the non-conforming platforms β she might not see the difference between -0.0 and +0.0 over there. π
β STANDARDS β
C11, POSIX.1-2008.
This function is defined in IEC 559 (and the appendix with recommended functions in IEEE 754/IEEE 854). certified. standardized. she's got receipts. π
π HISTORY π
C99, POSIX.1-2001, 4.3BSD. an elder icon. been serving magnitude-plus-sign realness since basically forever. π
π¦ SEE ALSO π¦
bestie reminder: she copies the sign bit, not the value, not the type, not your whole personality. magnitude from x, sign from y, that's the contract, don't go expecting anything else. π€
and that's the whole page, babe β this little manual came to you courtesy of Linux man-pages 6.20, dated 2026-02-08, for copysign(3). stan a tiny function that does exactly one thing and does it flawlessly. πβ¨ππ¦πΈ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms