Why Math.Ceiling returns double?

double has a greater value range than int:

The Double value type represents a
double-precision 64-bit number with
values ranging from negative
1.79769313486232e308 to positive 1.79769313486232e308, as well as positive or negative zero,
PositiveInfinity, NegativeInfinity,
and Not-a-Number (NaN).

Double complies with the IEC
60559:1989 (IEEE 754) standard for
binary floating-point arithmetic.

That standard says that double has a 52-bit mantissa, which means it can represent any integer up to 52 bits long without loss of precision.

Therefore if the input is large enough, the output doesn’t fit inside an int (which only has 32 bits).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)