1

What is the value set for NaN, POSITIVE_INFINITY and some other constants in Double class? From the source code, I see that they are set to themselves, but how does that work?

public final class Double extends Number implements Comparable<Double> {
    public static final double POSITIVE_INFINITY = POSITIVE_INFINITY;
    public static final double NEGATIVE_INFINITY = NEGATIVE_INFINITY;
    public static final double NaN = NaN;
    public static final double MAX_VALUE = MAX_VALUE;
    public static final double MIN_VALUE = MIN_VALUE;

    ...
}

Thanks.

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
  • Would be useful to mention the version of Java you are using – Thiyagu May 21 '18 at 04:40
  • 2
    Where do you see that? [At least here](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/Double.java/), they have values. – Andy Turner May 21 '18 at 04:41
  • Given that the source code that you posted above doesn't compile, I think that, most likely, there is some mixup on your part. Maybe you're using a decompiler in your IDE that is too smart for it's own good? In any case - voting to close to as "can't reproduce" - as it's formulated now you're asking about the reason for something that is not the case in reality. – Erwin Bolwidt May 21 '18 at 04:45
  • 1
    I wonder if this is basically just the way your IDE is presenting it to you. It is being "helpful", because in most cases, you're not looking at the source code of `Double`, so showing a constant's value that is equal to `Double.POSITIVE_INFINITY` as `POSITIVE_INFINITY` would make it more readable. – Andy Turner May 21 '18 at 04:47

1 Answers1

5

At least in OpenJDK 8, OpenJDK 9 and OpenJDK 10, they are in the source code:

public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
public static final double NaN = 0.0d / 0.0;  // (*)
public static final double MAX_VALUE = 0x1.fffffffffffffP+1023;
public static final double MIN_VALUE = 0x0.0000000000001P-1022;

(*) In case you're wondering about the "d"...

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
  • Sorry it's my bad. I was looking at the FernFlower decompiled code instead of sources in Eclipse. I can see the values declared. Sorry again and thanks. – Gurwinder Singh May 21 '18 at 11:22