Why do round() and ceil() not return an integer? Why do round() and ceil() not return an integer? c c

Why do round() and ceil() not return an integer?


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.

from the ceil(3) Linux man page.


That's because float's range is wider than int's. What would you expect to have if the value returned by these functions did not fit into an int? That would be undefined behaviour and you would be unable to check for that in your program.