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 ... printf("%f", ceil(-5.9)); Try it Yourself » · The ceil() function rounds a number UP to the nearest integer....
🌐
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
#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)); }
🌐
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.
🌐
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:
🌐
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.
🌐
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.
Find elsewhere
🌐
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
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › ceil-ceilf-ceill
ceil, ceilf, ceill | Microsoft Learn
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.
🌐
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
math.js
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 ...
🌐
Cppreference
en.cppreference.com › w › cpp › numeric › math › ceil.html
std::ceil, std::ceilf, std::ceill - cppreference.com
The library provides overloads of std::ceil for all cv-unqualified floating-point types as the type of the parameter.(since C++23) If no errors occur, the smallest integer value not less than num, that is ⌈num⌉, is returned. ... Errors are reported as specified in math_errhandling.
🌐
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....
🌐
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.
🌐
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
🌐
Linux Man Pages
man7.org › linux › man-pages › man3 › ceil.3.html
ceil(3) - Linux manual page
#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 ·