为什么浮点数有符号零?

2022-11-07Java开发问题
3

本文介绍了为什么浮点数有符号零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

为什么双打有 -0+0?有什么背景和意义?

解决方案

-0 (通常)被视为 0 *******.当 negative 浮点数非常接近于零以至于它可以被认为是 0 时,它可能会导致(要清楚,我指的是 )

用数学术语:

这说明了 0-0 在计算意义上的一个显着区别.

<小时>

这里有一些相关资源,其中一些已经提出.为了完整起见,我将它们包括在内:

  • 关于签名零的维基百科文章
  • "每个计算机科学家都应该知道的浮点运算知识"(参见有符号零部分)
  • (PDF) "Much Ado About Nothing's Sign Bit" - 一篇有趣的论文由 W. Kahan 撰写.

Why do doubles have -0 as well as +0? What is the background and significance?

解决方案

-0 is (generally) treated as 0 *******. It can result when a negative floating-point number is so close to zero that it can be considered 0 (to be clear, I'm referring to arithmetic underflow, and the results of the following computations are interpreted as being exactly ±0, not just really small numbers). e.g.

System.out.println(-1 / Float.POSITIVE_INFINITY);

-0.0

If we consider the same case with a positive number, we will receive our good old 0:

System.out.println(1 / Float.POSITIVE_INFINITY);

0.0


******* Here's a case where using -0.0 results in something different than when using 0.0:

System.out.println(1 / 0.0);
System.out.println(1 / -0.0);

Infinity
-Infinity

This makes sense if we consider the function 1 / x. As x approaches 0 from the +-side, we should get positive infinity, but as it approaches from the --side, we should get negative infinity. The graph of the function should make this clear:

(source)

In math-terms:

This illustrates one significant difference between 0 and -0 in the computational sense.


Here are some relevant resources, some of which have been brought up already. I've included them for the sake of completeness:

  • Wikipedia article on signed zero
  • "What Every Computer Scientist Should Know About Floating-Point Arithmetic" (See Signed Zero section)
  • (PDF) "Much Ado About Nothing's Sign Bit" - an interesting paper by W. Kahan.

这篇关于为什么浮点数有符号零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13