Yogesh Luthra - 3 months ago 5x

Java Question

can we compare POSITIVE_INFINITY of Double wrapper in Java?

Basically what would be the result of comparison between double a and double b, where both are set as Double.POSITIVE_INFINITY?

A related question, is double primitive a total order in Java?

Answer

`<`

and `>`

don't form a total order, but `Double.compare`

does.

`Double.POSITIVE_INFINITY`

compares as larger than anything but itself and `Double.NaN`

. If both are set as `Double.POSITIVE_INFINITY`

they will compare as equal.

Source (Stackoverflow)

Comments