文档章节

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
崇明
后端工程师
私信 提问
java中的NAN和INFINITY

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

李矮矮
2016/10/27
7
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
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

没有更多内容

加载失败,请刷新页面

加载更多

Java 源代码和 C 源代码的运行区别

与其他程序的执行方式和编译方式不同。 Java 源代码需要进行编译成字节码后在 Java 虚拟机上运行,这样 Java 程序能够保持独立性和跨平台功特性。 请参考下图。 https://www.cwiki.us/pages...

honeymose
今天
4
0
Apache限定目录解析PHP,限制user_agent,PHP相关的配置

Apache限定目录解析PHP 配置前访问upload/index.php [root@test-a ~]# curl -x192.168.77.139:80 'www.test.com/upload/index.php'This is upload diretory 配置,/usr/local/apache2.4/......

野雪球
今天
5
0
java.util.Concurrent.Exchanger源码

类图 源码: package java.util.concurrent;import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.atomic.AtomicReference;import java.util.concurrent......

狼王黄师傅
今天
6
0
Kubernetes里的secret最基本的用法

Secret解决了密码、token、密钥等敏感数据的配置问题,使用Secret可以避免把这些敏感数据以明文的形式暴露到镜像或者Pod Spec中。 Secret可以以Volume或者环境变量的方式使用。 使用如下命令...

JerryWang_SAP
昨天
5
0
2018-11-20学习笔记

1. python数据类型: 给变量赋值什么样的值,变量就是什么样的类型 给变量赋值整数,变量就是整数类型 给变量赋值字符串,变量就是字符串类型 123 和“123”一样吗? 在python中 单引号 与双...

laoba
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部