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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms