Why is the return type of the "ceil()" function "double" instead of some integer type?

A double has a range that can be greater than any integer type. Returning double is the only way to ensure that the result type has a range that can handle all possible input.


ceil() takes a double as an argument. So, if it were to return an integer, what integer type would you choose that can still represent its ceiled value? Whatever may be the type, it should be able to represent all possible double values.

The integer type that can hold the highest possible value is uintmax_t. But that doesn't guarantee it can hold all double values even in some implementations it can.

So, it makes sense to return a double value for ceil(). If an integer value is needed, then the caller can always cast it to the desired integer type.