Possible Duplicate:
Why doesn't Math.Round/Floor/Ceiling return long or int?
msdn defined this method:Returns the smallest integer greater than or equal to the specified double-precision floating-point number.
but in fact,it is
public static double Ceiling (
double a
)
why not return int directly? what does microsoft think of ?
It’s because the range of a
double(±5.0 × 10−324 to ±1.7 × 10308) is much greater than the range of anint(-2,147,483,648 to 2,147,483,647). If the return type wereintmany possible inputs would fail. For exampleMath.Ceilingmight be forced to throw anOverflowExceptionin a checked context, or it might even return an incorrect result in an unchecked context. This is undesirable behaviour.Also some special values such as
NaNandPositiveInfinitycan be returned by this method. This is only possible if the return type isdouble.If you believe that the result will fit into an int, you can add an explicit cast: