The range of double
is much wider than the range of int
or long
. Consider this code:
double d = 100000000000000000000d;
long x = Math.Floor(d); // Invalid in reality
The integer is outside the range of long
- so what would you expect to happen?
Typically you know that the value will actually be within the range of int
or long
, so you cast it:
double d = 1000.1234d;
int x = (int) Math.Floor(d);
but the onus for that cast is on the developer, not on Math.Floor
itself. It would have been unnecessarily restrictive to make it just fail with an exception for all values outside the range of long
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…