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
xoryis aNaN, aNaNis 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, orHUGE_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 β
errnois set toERANGE. 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
- Copyright 2003, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms