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: x is an infinity and y is not a NaN β€” errno is set to EDOM (but see BUGS). An invalid floating-point exception (FE_INVALID) is raised. These functions do not set errno for this case.
  • Domain error: y is zero β€” errno is set to EDOM. An invalid floating-point exception (FE_INVALID) is raised.
😭 not the double-dipping in that first bullet β€” it says errno gets set to EDOM and then immediately says these functions don't set errno for 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 🫢

div(3), fmod(3), remquo(3)


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