Try this out:

#define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X))
#define CEILING_NEG(X) (int)(X)
#define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) )

Check out the link for comments, proof and discussion: http://www.linuxquestions.org/questions/programming-9/ceiling-function-c-programming-637404/

Thanks to Vilhelm Gray and carveone for pointing out that the linked definition of CEILING_NEG(X) is incorrect.

Answer from nintendo on Stack Overflow
🌐
W3Schools
w3schools.com › c › ref_math_ceil.php
C Math ceil() Function
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate · ❮ Math Functions · Round numbers up to the nearest integer: printf("%f", ceil(0.60)); printf("%f", ...
🌐
Programiz
programiz.com › c-programming › library-function › math.h › ceil
C ceil() - C Standard Library
Become a certified C programmer. Try Programiz PRO! ... The ceil() function takes a single argument and returns the nearest integer number. For example: If 2.3 is passed to ceil(), it will return 3. The function is defined in <math.h> header file.
🌐
Cppreference
en.cppreference.com › w › c › numeric › math › ceil
ceil, ceilf, ceill - cppreference.com
May 23, 2024 - #include <math.h> #include <stdio.h> int main(void) { printf("ceil(+2.4) = %+.1f\n", ceil(2.4)); printf("ceil(-2.4) = %+.1f\n", ceil(-2.4)); printf("ceil(-0.0) = %+.1f\n", ceil(-0.0)); printf("ceil(-Inf) = %+f\n", ceil(-INFINITY)); }
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-ceil-function
C ceil() Function - GeeksforGeeks
July 7, 2024 - C ceil() is a built-in library function that computes the smallest integer value greater than or equal to the given floating-point number. It is defined inside the <math.h> header file with its prototype as follows:
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_ceil.htm
C library - ceil() function
The C library ceil() function of type double accept the single argument(x) that returns the smallest integer value greater than or equal to, by the given value. This method rounded up the nearest integer.
🌐
Cplusplus
cplusplus.com › reference › cmath › ceil
Ceil
double ceil (double x); float ceil (float x);long double ceil (long double x); double ceil (T x); // additional overloads for integral types ... Rounds x upward, returning the smallest integral value that is not less than x. Header <tgmath.h> provides a type-generic macro version of this function. Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › math_h › ceil.php
C Language: ceil function (Ceiling)
math.h · In the C Programming Language, the ceil function returns the smallest integer that is greater than or equal to x (ie: rounds up the nearest integer). The syntax for the ceil function in the C Language is: double ceil(double x); x · The value to round up to the nearest integer.
Find elsewhere
🌐
Vultr
docs.vultr.com › clang › standard-library › math-h › ceil
C math.h ceil() - Round Up to Integer | Vultr Docs
September 27, 2024 - It ensures every item has a package, even if the last package is not completely full. The ceil() function in the math.h library is an invaluable tool in C for rounding up floating-point numbers to the nearest integer.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › ceil-ceilf-ceill
ceil, ceilf, ceill | Microsoft Learn
July 9, 2025 - In a C program, unless you're using the <tgmath.h> macro to call this function, ceil always takes and returns a double. If you use the <tgmath.h> ceil() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.
🌐
GitHub
github.com › rofl0r › musl › blob › master › src › math › ceil.c
musl/src/math/ceil.c at master · rofl0r/musl
static const double_t toint = 1/EPS; · double ceil(double x) { union {double f; uint64_t i;} u = {x}; int e = u.i >> 52 & 0x7ff; double_t y; · if (e >= 0x3ff+52 || x == 0) return x; /* y = int(x) - x, where int(x) is an integer neighbor of x */ if (u.i >> 63) y = x - toint + toint - x; else ·
Author   rofl0r
🌐
Scaler
scaler.com › topics › ceil-function-in-c
Ceil Function in C - Scaler Topics
April 20, 2022 - The ceil() function in C, declared in the math.h header file, is used to find the nearest integral value, which is not less than the given number(provided as a parameter to the function).
🌐
Math.js
mathjs.org › docs › reference › functions › ceil.html
Function ceil
math.ceil(c, 1) // returns Complex 3.3 - 2.7i const unit = math.unit('3.241 cm') const cm = math.unit('cm') const mm = math.unit('mm') math.ceil(unit, 1, cm) // returns Unit 3.3 cm ...
🌐
Codecademy
codecademy.com › forum_questions › 4f35e646fe0083000301a5e5
1.2: Why not use Math.ceil? | Codecademy
Expected " + Math.round(nrols/... for every random value you will get from Math.random(). Ceil returns the smallest integer GREATER THAN or equal to a number....
🌐
O'Reilly
oreilly.com › library › view › c-in-a › 0596006977 › re31.html
ceil - C in a Nutshell [Book]
December 16, 2005 - Content preview from C in a Nutshell ... double ceill( long double x ); (C99) The ceil() function returns the smallest integer that is greater than or equal to its argument....
Authors   Peter PrinzTony Crawford
Published   2005
Pages   618
🌐
Reddit
reddit.com › r/learnprogramming › writing a ceiling function in c
r/learnprogramming on Reddit: Writing a ceiling function in C
September 18, 2013 -

I'm trying to write a function that (kind of) emulates the ceiling function in the math library, in a way that is more useful for my purposes. The code I've written is not working as expected. It should take two integer arguments, divide one by the other, and round up to the nearest integer no matter what the result is.

Ex: 2/2=1 --> answer is 1; 10/3=3.333... --> round up to 4.

This is my code:

int ceiling(int number, int value){
    float a = number/value;
    int b = number/value;
    float c = a - b;
    if(c!=0){
        b=b+1;
    }
    return b;
}

Using the examples above,

ceiling(2,2); would return 1, as expected.

ceiling(10,3); returns 3, when it should return 4.

My thought process is that if a is a float, then 10/3 should be 3.33333..., and if b is an int, then 10/3 should be 3. If c is a float, a-b should be 0.33333..., then since c!=0, ceiling should increment b and return that value. Where am I going wrong?

🌐
The Open Group
pubs.opengroup.org › onlinepubs › 009695199 › functions › ceil.html
ceil
Upon successful completion, ceil(), ceilf(), and ceill() shall return the smallest integral value not less than x, expressed as a type double, float, or long double, respectively.
🌐
KooR
koor.fr › C › cmath › ceil.wp
KooR.fr - Fonctions ceil, ceilf et ceill - Langage C
Les fonctions ceilf et ceill ont été ajoutées dans C99. value : la valeur à partir de laquelle calculer l'arrondi « plafond ». Renvoie l'arrondi entier supérieur. Il est à noter que la librairie mathématique doit être ajoutée durant ...