这三个特殊的浮点值是什么意思:正无穷大,负无穷大,NaN? [英] What do these three special floating-point values mean: positive infinity, negative infinity, NaN?

查看:425
本文介绍了这三个特殊的浮点值是什么意思:正无穷大,负无穷大,NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在代码中使用它们,会导致NaN(不是数字)? href =http://introcs.cs.princeton.edu/java/91float/ =nofollow noreferrer>如果你想了解更多关于Java中的浮点数的信息,这可能是一个很好的参考。

正无穷大是一个很大的正数,不能正常表示。负无限是一个负数,如此大以至于无法正常表示。 NaN的意思是不是一个数字,它是一个数学运算的结果,它不产生类似数字0的数字。在Java中,Double和Float类都有常数来代表所有三种情况。他们是POSITIVE_INFINITY,NEGATIVE_INFINITY和NaN。

另外考虑这个:

pre $ double a = Math.pow(10,600) - Math.pow(10,600); // == NaN

在数学上,每个人都可以看到它是0.但是对于机器来说,一个Infinity - Infinity(相同的Rank),这确实是NaN。

How can we use them in our codes, and what will cause NaN(not a number)?

解决方案

This may be a good reference if you want to learn more about floating point numbers in Java.

Positive Infinity is a positive number so large that it can't be represented normally. Negative Infinity is a negative number so large that it cannot be represented normally. NaN means "Not a Number" and results from a mathematical operation that doesn't yield a number- like dividing 0 by 0.

In Java, the Double and Float classes both have constants to represent all three cases. They are POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN.

Plus consider this:

double a = Math.pow(10, 600) - Math.pow(10, 600); //==NaN

Mathematically, everybody can see it is 0. But for the machine, it is an "Infinity" - "Infinity" (of same Rank), which is indeed NaN.

这篇关于这三个特殊的浮点值是什么意思:正无穷大,负无穷大,NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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