ceil(3)

โœจ ceil(3) โ€” the ceiling function, bestie โœจ

okay so this is from the Library Functions Manual, and we're talking about ceil, ceilf, and ceill โ€” the ceiling function: smallest integral value not less than argument. ๐ŸŽ€


๐Ÿ’– NAME ๐Ÿ’–

ceil, ceilf, ceill โ€” ceiling function: smallest integral value not less than argument ๐Ÿฆ‹


๐Ÿ“š LIBRARY ๐Ÿ“š

Math library (libm, link it with -lm) ๐Ÿ”ฅ


โœจ SYNOPSIS โœจ

#include <math.h>

double ceil(double x);
float ceilf(float x);
long double ceill(long double x);

๐ŸŒธ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): ๐ŸŒธ

ceilf(), ceill():
    _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
        || /* Since glibc 2.19: */ _DEFAULT_SOURCE
        || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

likeโ€ฆ yes you have to define the right macro first, it's giving โœจbureaucracyโœจ but we move ๐Ÿ’…


๐Ÿ’… DESCRIPTION ๐Ÿ’…

So these functions return the smallest integral value that is not less than x. That's literally the whole vibe. ๐Ÿซถ

For example, ceil(0.5) is 1.0, and ceil(-0.5) is 0.0. no cap. ๐Ÿ˜ญ


๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

These functions return the ceiling of x. ๐Ÿ‘‘

If x is integral, +0, -0, NaN, or infinite, x itself is returned. so it just hands you back your own little guy, unchanged. iconic. ๐Ÿ’œ


๐Ÿ’€ ERRORS ๐Ÿ’€

No errors occur. not one. zero. the girl is flawless. โœจ


๐Ÿ‘‘ ATTRIBUTES ๐Ÿ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • Interface: ceil(), ceilf(), ceill()
    • Attribute: Thread safety
    • Value: MT-Safe โœ…

(it was a table in the original, but tables are not it, so here's the tea in bullet form ๐Ÿ“)


๐ŸŒˆ STANDARDS ๐ŸŒˆ

C11, POSIX.1-2008. periodt. ๐Ÿ’…


๐Ÿฆ‹ HISTORY ๐Ÿฆ‹

C99, POSIX.1-2001.

The variant returning double also conforms to SVr4, 4.3BSD, C89.

SUSv2 and POSIX.1-2001 contain text about overflow (which might set errno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the result cannot overflow on any current machine, so this error-handling stuff was just nonsense. ๐Ÿ˜ญ (More precisely, overflow can happen only when the maximum value of the exponent is smaller than the number of mantissa bits. For the IEEE-754 standard 32-bit and 64-bit floating-point numbers the maximum value of the exponent is 127 (respectively, 1023), and the number of mantissa bits including the implicit bit is 24 (respectively, 53).) This was removed in POSIX.1-2008.

๐Ÿšจ okay so listen up bestie because this part is IMPORTANT ๐Ÿšจ The integral value returned by these functions may be too large to store in an integer type (int, long, etc.). To avoid an overflow, which will produce undefined results, an application should perform a range check on the returned value before assigning it to an integer type.

so like. check before you cast. do not just yolo it into an int. that's how you get cursed undefined behaviour and nobody wants that energy. ๐Ÿ™ˆ


๐Ÿ’– SEE ALSO ๐Ÿ’–

floor(3), lrint(3), nearbyint(3), rint(3), round(3), trunc(3) โ€” the whole rounding friend group, go say hi ๐ŸŒธ


and that's the page!! this one's from Linux man-pages 6.20, dated 2026-02-08, and it's the ceil(3) entry obviously ๐Ÿ’… thanks for reading bestie, go round your floats 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