As explained here, Math.Ceiling returns: "The smallest integral value that is greater than or equal to a". But later it says: "Note that this method returns a Double type instead of an integral type." I'm just wondering why?
+16
A:
Because a double has a much bigger maximum value than an integer supports.
Asking for the ceiling on a double
that has a value greater than Int32.MaxValue
(or even Int64.MaxValue
) would not be possible if it returned an integer.
Jeff Yates
2010-03-03 13:41:33
thought it was something like that. Thanks
Anders Rune Jensen
2010-03-03 13:44:59
@anders: imagine 10^-1 it is: 0.01 -> double...
blgnklc
2010-03-03 13:52:52
@blgnklc: 10^-1 is 0.1, not 0.01 . . . but anyway, what does that have to do with Math.Ceiling?
Tim Goodman
2010-03-04 10:50:18
+2
A:
I think the purpose of that 'note' is to make sure people aren't led astray by the phrase 'integral value' into thinking that the return value is necessarily of an integer type. As other answers point out, not all integral values can be stored in integer-y types.
AakashM
2010-03-03 13:45:52
It would have been nice if they would link to the formal definition of integral :-)
Anders Rune Jensen
2010-03-03 13:58:30
@Anders: It would have been nice if they just said "returns a double type whose value is the smallest integer greater than or equal to a". They're basically just using "integral value" to mean "integer" (which is perfectly correct, but I personally prefer to avoid this usage because the word "integral" makes people think of calculus and such.)
Tim Goodman
2010-03-04 10:59:52
Yeah agree, that's much better. Why isn't it a wiki so that we can fix it? :-)
Anders Rune Jensen
2010-03-05 09:27:43