为什么Math.floor会返回一个双精度数?

编程入门 行业动态 更新时间:2024-10-15 08:23:28
本文介绍了为什么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会返回一个双精度数?

本文发布于:2023-10-24 21:13:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525025.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精度   Math   floor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!