Why does Math.floor return a double?

前端 未结 6 2027
-上瘾入骨i
-上瘾入骨i 2020-12-13 23:05

Official Javadoc says that Math.floor() returns a double that is \"equal to a mathematical integer\", but then why shouldn\'t it return an in

6条回答
  •  被撕碎了的回忆
    2020-12-13 23:31

    According to the same Javadoc:

    If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. Can't do that with an int.

    The largest double value is also larger than the largest int, so it would have to be a long.

提交回复
热议问题