Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ceiling in .NET return a Double and not an integer?

Tags:

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?

like image 847
Anders Rune Jensen Avatar asked Mar 03 '10 13:03

Anders Rune Jensen


2 Answers

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.

like image 106
Jeff Yates Avatar answered Oct 05 '22 13:10

Jeff Yates


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.

like image 20
AakashM Avatar answered Oct 05 '22 13:10

AakashM