相关疑难解决方法(0)

为什么f在浮动值之后放置?

我不知道为什么在Java或其他语言中浮点值之后放置f或F?例如,

float fVariable = 12.3f;
Run Code Online (Sandbox Code Playgroud)

除了表明这是浮点值以外的任何其他功能?

java floating-point

69
推荐指数
4
解决办法
7万
查看次数

为什么Double.NaN = 0.0d/0.0的定义中有"d"?

我刚刚看到了NaNin 的定义Double.class.它说:

 /**
   * A constant holding a Not-a-Number (NaN) value of type
   * {@code double}. It is equivalent to the value returned by
   * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
   */
  public static final double NaN = 0.0d / 0.0;
Run Code Online (Sandbox Code Playgroud)

我知道,根据Java规范这些文字代表了同一个号码:0.0,0.0d,和0.0D.

另外对于其他常量,他们没有使用'd'后缀:

public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
Run Code Online (Sandbox Code Playgroud)

为什么他们需要在NaN定义中将后缀d写入0.0的第一部分?

这是故意的还是偶然的?

java

27
推荐指数
3
解决办法
6129
查看次数

初始化变量的方式有所不同:float f = 100; 或浮动f = 100f?

Java的.

我初始化变量的方式有区别吗:

float f = 100; //implies a cast from integer to float
Run Code Online (Sandbox Code Playgroud)

要么

float f = 100f; //simply a float initialization
Run Code Online (Sandbox Code Playgroud)

结果会有所不同吗?

在这里,我尝试使用非常大的浮子,但看起来精度的损失是相同的.

float f1 = (float)2000000000;
float f2 = (float)2000000050;
float f3 = 2000000000f;
float f4 = 2000000050f;
System.out.println(f1 + " " + f2 + " " + (f1==f2) + " " + f3 + " " + f4 + " "+ (f3==f4) );
Run Code Online (Sandbox Code Playgroud)

- > 2.0E9 2.0E9 true 2.0E9 2.0E9 true

与双打有什么区别?

java floating-point

5
推荐指数
1
解决办法
256
查看次数

标签 统计

java ×3

floating-point ×2