Why does Math.floor return a double?

前端 未结 6 2015
-上瘾入骨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:41

    So that error and other non integer values can correctly cascade through a series of calculations.

    For instance, if you feed Not a Number (NaN) into Math.floor, it'll pass it along.

    If it returned integer it couldn't pass these status or errors along, and you could get bad results from an earlier calculation that look good but are wrong after further processing.

提交回复
热议问题