Possible Duplicate:
Why does Math.Floor(Double) return a value of type Double?
Why does C# Math.Floor()
return double
instead of int
From the MSDN Docs:
Returns the largest integer less than or equal to the specified double-precision floating-point number
it says it returns an integer. Its ok to return a double
, I can always cast it to an int
but its just quite strange, isn't it?
Not really, considering that a
double
can be a much higher magnitude than anint
. You wouldn't want to overflow an int with the large value that a double could be.Just to show you what I mean:
Double.MaxValue = 1.7976931348623157E+308
Integer.MaxValue = 2,147,483,647
So you could have a double that is 3,000,000,000.50 and floor it, which would overflow the max value of an int.
Because the INPUT is a double, the OUTPUT must also be a double, or a lot of potential output would not fit into the output variable.
In mathematical terms, the domain and the range of the function must have the same size.