0

I found that this code work well and when I print it I have "Infinity". I don't understand how can we put value Infinity in primitive type, I thought that it will be error.

  String s = "Infinity";
    double d  = Double.valueOf(s);
    System.out.println(d);
  • 3
    with `Double.POSITIVE_INFINITY` and `Double.NEGATIVE_INFINITY`? – SomeJavaGuy Nov 10 '15 at 13:18
  • What do you mean by infinity? Really, you ought not to model it at all. – Bathsheba Nov 10 '15 at 13:21
  • [https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers](https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers) – Boann Nov 10 '15 at 15:00
  • 1
    The fact that the data type is called "primitive" has nothing to do with it. A `double` has 64 bits. That means, there are 2^64 distinct `double` values. One of those values is called _positive infinity_, and another one is called _negative infinity_. – Solomon Slow Nov 10 '15 at 17:57

0 Answers0