首页 / JAVA / 核心Java上除以0.0
核心Java上除以0.0
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了核心Java上除以0.0,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1620字,纯文字阅读大概需要3分钟。
内容图文
![核心Java上除以0.0](/upload/InfoBanner/zyjiaocheng/787/b67e898a910a49f5bc74064ff70ec5d0.jpg)
我在java中听到了一个转折点.如果有人知道你被要求分享的正当理由.
问题是:
double result1 = 1.0/0.0;
sop(result1); // output Infinity
double result2 = 0.0/0.0;
sop(result2); // output NaN
浮点变量也是如此.但对于int类型,它引发了ArithmeticException.为什么?
注意:我使用的是jdk 1.7
解决方法:
您不能使用int表示无穷大或NAN.
从JLS起
The result of a floating-point division is determined by the rules of
IEEE 754 arithmetic:Division of a nonzero finite value by a zero results in a signed
infinity. The sign is determined by the rule stated above.
Why doesn’t division by zero (or overflow, or underflow) stop the
program or trigger an error? Why does a standard on numbers include
“not-a-number” (NaN)? The 754 model encourages robust programs. It is
intended not only for numerical analysts but also for spreadsheet
users, database systems, or even coffee pots. The propagation rules
for NaNs and infinities allow inconsequential exceptions to vanish.
Similarly, gradual underflow maintains error properties over a
precision’s range.When exceptional situations need attention, they can be examined
immediately via traps or at a convenient time via status flags. Traps
can be used to stop a program, but unrecoverable situations are
extremely rare. Simply stopping a program is not an option for
embedded systems or network agents. More often, traps log diagnostic
information or substitute valid results.Flags offer both predictable control flow and speed. Their use
requires the programmer be aware of exceptional conditions, but flag
stickiness allows programmers to delay handling exceptional conditions
until necessary.
内容总结
以上是互联网集市为您收集整理的核心Java上除以0.0全部内容,希望文章能够帮你解决核心Java上除以0.0所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。