文档章节

How can I initialize a double variable to infinity

Oscarfff
 Oscarfff
发布于 2015/06/09 10:26
字数 227
阅读 47
收藏 0

Q. How can I initialize a double variable to infinity?

A. Java has built-in constants available for this purpose: Double.POSITIVE_INFINITY

and Double.NEGATIVE_INFINITY.

Q. Can you compare a double to an int?

A. Not without doing a type conversion, but remember that Java usually does the requisite type conversion automatically. For example, if x is an int with the value 3, then

the expression (x < 3.1)  is true—Java converts x to double (because 3.1 is a double

literal) before performing the comparison.

Q. What are the values of 1/0 and 1.0/0.0 as Java expressions?

A. The first generates a runtime exception for division by zero (which stops your program because the value is undefined); the second has the value Infinity

Q. Why do we say (a && b) and not (a & b) ?

A. The operators &, | , and ^ are bitwise logical operations for integer types that do and,

or, and exclusive or (respectively) on each bit position. Thus the value of 10&6 is 14 and

the value of 10^6 is 12. We use these operators rarely (but occasionally) in this book.

The operators && and ||  are valid only in boolean expressions are included separately

because ofshort-circuiting: an expression is evaluated left-to-right and the evaluation

stops when the value is known.


© 著作权归作者所有

共有 人打赏支持
Oscarfff
粉丝 72
博文 815
码字总数 96913
作品 0
崇明
后端工程师
JavaScript Primitive Data Types

JavaScript Primitive Data Types Primitive data types Any value that you use is of a certain type. In JavaScript, there are just a few primitive data types: 1. Number: This inc......

秋风醉了
2014/07/16
0
0
java中的NAN和INFINITY

java浮点数运算中有两个特殊的情况:NAN、INFINITY。 1、INFINITY: 在浮点数运算时,有时我们会遇到除数为0的情况,那java是如何解决的呢? 我们知道,在整型运算中,除数是不能为0的,否则...

李矮矮
2016/10/27
7
0
Creating a Turing Machine in Python – Part 2

In the last part, we covered the theory of Turing machines and created the basic project structure and classes. Now we are going to implement those classes one by one. direction......

Philipp_Engelmann
2017/12/22
0
0
C# 中的 Infinity 和 NaN

C#语言中,对于 int,long 和 decimal类型的数,任何数除以 0 所得的结果是无穷大,不在int,long 和 decimal 类型的范围之内,所以计算 6/0 之类的表达式会出错。 但是,double 和 float 类...

ucliaohh
2015/09/02
702
2
聊聊Guava的RateLimiter

序 本文主要研究一下Guava的RateLimiter RateLimiter guava-26.0-jre-sources.jar!/com/google/common/util/concurrent/RateLimiter.java 这里主要看acquire以及tryAcquire方法 acquire主要依......

go4it
08/31
0
0

没有更多内容

加载失败,请刷新页面

加载更多

你为什么在Redis里读到了本应过期的数据

一个事故的故事 晚上睡的正香突然被电话吵醒,对面是开发焦急的声音:我们的程序在访问redis的时候读到了本应过期的key导致整个业务逻辑出了问题,需要马上解决。 看到这里你可能会想:这是不...

IT--小哥
今天
2
0
祝大家节日快乐,阖家幸福! centos GnuTLS 漏洞

yum update -y gnutls 修复了GnuTLS 漏洞。更新到最新 gnutls.x86_64 0:2.12.23-22.el6 版本

yizhichao
昨天
5
0
Scrapy 1.5.0之选择器

构造选择器 Scrapy选择器是通过文本(Text)或 TextResponse 对象构造的 Selector 类的实例。 它根据输入类型自动选择最佳的解析规则(XML vs HTML): >>> from scrapy.selector import Sele...

Eappo_Geng
昨天
4
0
Windows下Git多账号配置,同一电脑多个ssh-key的管理

Windows下Git多账号配置,同一电脑多个ssh-key的管理   这一篇文章是对上一篇文章《Git-TortoiseGit完整配置流程》的拓展,所以需要对上一篇文章有所了解,当然直接往下看也可以,其中也有...

morpheusWB
昨天
5
0
中秋快乐!!!

HiBlock
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部