fdim(3)

πŸ’– fdim(3) β€” the "positive difference" girlies πŸ’–

okay so bestie, welcome to the fdim family: that's fdim, fdimf, and fdiml β€” three icons, one job: positive difference. this is a page from the Library Functions Manual, and it's giving "small function, big feelings" ✨


🌸 LIBRARY 🌸

Math library, duh β€” link it with -lm or she will Not Load. <em>cries in undefined reference</em> 😭


πŸŽ€ SYNOPSIS πŸŽ€

#include <math.h>

double fdim(double x, double y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y);

πŸ¦‹ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

  • fdimf(), fdiml(): _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L

like, yes, you need the macros for the f and l versions. it's a whole thing. πŸ™ˆ


🌈 DESCRIPTION 🌈

so these functions return the positive difference β€” that's literally max(x-y,0), no cap β€” between their arguments.

that's it. that's the function. she takes x and y, she does x-y, and if that came out negative she just… doesn't. she clamps that baby to 0. main character energy, honestly. πŸ‘‘


⭐ RETURN VALUE ⭐

  • On success, these functions return the positive difference. slay. ✨
  • If x or y is a NaN, a NaN is returned. it's giving "we don't know her either" πŸ’€
  • If the result overflows, a range error occurs, and the functions return HUGE_VAL, HUGE_VALF, or HUGE_VALL, respectively. big number, absolutely feral. πŸ”₯

😭 ERRORS 😭

need the deets on how to tell if an error even happened while calling these? go read math_error(7), she explains everything.

the following errors can occur:

  • Range error: result overflow β€” errno is set to ERANGE. An overflow floating-point exception (FE_OVERFLOW) is raised. so yeah, she overflowed and she's loud about it. πŸ“£

πŸ’… ATTRIBUTES πŸ’…

for the whole explanation of the terms used here, see attributes(7).

(gonna bullet this out bc tables are not the vibe on a terminal okay)

  • fdim(), fdimf(), fdiml() β€” Thread safety: MT-Safe

MT-Safe!! she's safe in threads!! we love a secure queen 🫢


πŸ‘‘ STANDARDS πŸ‘‘

C11, POSIX.1-2008. certified, standardised, official. periodt.


πŸ•°οΈ HISTORY πŸ•°οΈ

  • glibc 2.1.
  • C99, POSIX.1-2001.

she's been around. she's a legacy icon. πŸ’œ


πŸ™ˆ BUGS πŸ™ˆ

Before glibc 2.24 on certain architectures (e.g., x86, but not x86_64) these functions did not set errno.

so if you're on old glibc on the wrong architecture and you're checking errno… bestie she's not filling that in. not her fault, it's a whole historical situation. 😭

fr fr: don't trust errno from these on that combo. that's a real caveat, not me being dramatic (well, a little bit of me being dramatic).

🌟 SEE ALSO 🌟


and that's the whole page, bestie! written up in the Linux man-pages 6.20 era, dated 2026-02-08, filed under fdim(3). go forth and clamp your differences. mwah πŸ’‹

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