24

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?

3 Answers 3

31

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.

2
  • thought it was something like that. Thanks Mar 3, 2010 at 13:44
  • 4
    @blgnklc: 10^-1 is 0.1, not 0.01 . . . but anyway, what does that have to do with Math.Ceiling? Mar 4, 2010 at 10:50
2

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.

3
  • It would have been nice if they would link to the formal definition of integral :-) Mar 3, 2010 at 13:58
  • 1
    @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.) Mar 4, 2010 at 10:59
  • Yeah agree, that's much better. Why isn't it a wiki so that we can fix it? :-) Mar 5, 2010 at 9:27
1

The range of the largest integer type is still much smaller than that of Double. So a lot of valid double values would not have a Ceiling().

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.