为什么Math.floor会返回一个双精度数? [英] Why does Math.floor return a double?

查看:144
本文介绍了为什么Math.floor会返回一个双精度数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方javadoc Math.floor返回一个等于数学整数的double,但是为什么不能返回一个int?

Official javadoc says that Math.floor returns a double that is "equal to a mathematical integer", but then why shouldn't it return an int?

推荐答案

根据相同的javadoc:

According to the same javadoc:

如果参数为NaN或无穷大或正零或负零,则结果与参数相同。不能用int做到这一点。

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.

最大的double值也大于最大的int,所以它必须是一个很长的。

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

这篇关于为什么Math.floor会返回一个双精度数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆