I know that C++ provides us with a ceil function. For practice, I was wondering how can we implement the ceil function in C++. The signature of the method is public static
Something like this:
double param, fractpart, intpart;
param = 3.14159265;
fractpart = modf (param , &intpart);
int intv = static_cast(intpart); // can overflow - so handle that.
if (fractpart > some_epsilon)
++intv;
You just need to define some_epsilon value to whatever you want the fractional part to be bigger than before the integer part is incremented. Other things to consider are sign (i.e. if the value is negative etc.)