remainder(3)
πΈ NAME πΈ
drem, dremf, dreml, remainder, remainderf, remainderl β the floating-point remainder function π
okay so bestie, this is remainder(3), and she's giving math girlie energy. Same family, six sisters: remainder and her f/l variants (float and long double, obvs), plus the ancient deprecated trio drem, dremf, dreml who are literally the same thing wearing a vintage fit. π
π LIBRARY π
Math library (libm, -lm)
so like, you gotta link -lm, no cap. β¨
π¦ SYNOPSIS π¦
#include <math.h>
double remainder(double x, double y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
/* Obsolete synonyms */
[[deprecated]] double drem(double x, double y);
[[deprecated]] float dremf(float x, float y);
[[deprecated]] long double dreml(long double x, long double y);
π Feature Test Macro Requirements for glibc (see feature_test_macros(7)): π
remainder():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| _XOPEN_SOURCE >= 500
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
remainderf(), remainderl():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
drem(), dremf(), dreml():
/* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
ngl the drem girls need extra paperwork to even compile. she's high-maintenance like that. π
π DESCRIPTION π
These functions compute the remainder of dividing x by y. The return value is x-n*y, where n is the value x / y, rounded to the nearest integer. If the absolute value of x-n*y is 0.5, n is chosen to be even. π«Ά
so basically it's not just x % y energy β it rounds to the nearest whole number instead of truncating, and when it's a perfect tie at 0.5 it snatches the even n (that's the "round half to even" thing, iykyk). π
These functions are unaffected by the current rounding mode (see fenv(3)).
periodt β your fesetround(3) shenanigans do not touch these girls. they have their own rules. π
The drem() function does precisely the same thing.
β RETURN VALUE β
On success, these functions return the floating-point remainder, x-n*y. If the return value is 0, it has the sign of x. π
If x or y is a NaN, a NaN is returned.
If x is an infinity, and y is not a NaN, a domain error occurs, and a NaN is returned.
If y is zero, and x is not a NaN, a domain error occurs, and a NaN is returned.
π₯ ERRORS π₯
See math_error(7) for information on how to determine whether an error has occurred when calling these functions.
The following errors can occur:
- Domain error:
xis an infinity andyis not a NaN βerrnois set toEDOM(but see BUGS). An invalid floating-point exception (FE_INVALID) is raised. These functions do not seterrnofor this case. - Domain error:
yis zero βerrnois set toEDOM. An invalid floating-point exception (FE_INVALID) is raised.
π not the double-dipping in that first bullet β it sayserrnogets set toEDOMand then immediately says these functions don't seterrnofor this case. yes, that's really what the page says. that's why BUGS is below. read it, bestie. π«
π§ ATTRIBUTES π§
For an explanation of the terms used in this section, see attributes(7).
drem(),dremf(),dreml(),remainder(),remainderf(),remainderl()β Thread safety: MT-Safe
slay, all six of them are MT-Safe, so go wild in your threads. π
π STANDARDS π
remainder()remainderf()remainderl()
C11, POSIX.1-2008.
drem()dremf()dreml()
None.
the drem girlies are literally standardized by nobody. she's a free spirit. π
π HISTORY π
remainder()remainderf()remainderl()
C99, POSIX.1-2001.
drem()β 4.3BSD.dremf()dreml()
Tru64, glibc2.
π BUGS π
Before glibc 2.15, the call
remainder(nan(""), 0);
returned a NaN, as expected, but wrongly caused a domain error. Since glibc 2.15, a silent NaN (i.e., no domain error) is returned.
Before glibc 2.15, errno was not set to EDOM for the domain error that occurs when x is an infinity and y is not a NaN.
ancient glibc behavior bestie. if you're on anything modern you're chilling, but now you know why that weird errno wording up there exists. π
β¨ EXAMPLES β¨
The call "remainder(29.0, 3.0)" returns -1.
π«Ά SEE ALSO π«Ά
and that's the whole page, bestie!! π this was remainder(3) from Linux man-pages 6.20, dated 2026-02-08. go forth and compute remainders responsibly, 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: 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