elect
05/07/2019, 9:07 AM0f == (-0f)
as false
, which is wrongDias
05/07/2019, 9:24 AMAlthough negative zero and positive zero are generally considered equal for comparison purposes, some programming language relational operators and similar constructs treat them as distinct. According to the Java Language Specification,[5] comparison and equality operators treat them as equal, but Math.min() and Math.max() distinguish them (officially starting with Java version 1.1 but actually with 1.1.1), as do the comparison methods equals(), compareTo() and even compare() of classes Float and Double
karelpeeters
05/07/2019, 9:27 AMtrue
with false
.Dias
05/07/2019, 9:30 AMkarelpeeters
05/07/2019, 9:30 AMAccording to the Java Language Specification,[5] comparison and equality operators treat them as equal
Dias
05/07/2019, 9:31 AMbut Math.min() and Math.max() distinguish them (officially starting with Java version 1.1 but actually with 1.1.1), as do the comparison methods equals(), compareTo() and even compare() of classes Float and Double
Dias
05/07/2019, 9:31 AMkarelpeeters
05/07/2019, 9:31 AM==
, but not according to Float.equals
.karelpeeters
05/07/2019, 9:32 AMjava.lang.Float.equals
docs:
If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f==-0.0f has the value true.
Dias
05/07/2019, 9:33 AMkarelpeeters
05/07/2019, 9:36 AMval posPrimitive: Float = 0.0f
val negPrimitive: Float = -0.0f
val posBoxed: Float? = posPrimitive
val negBoxed: Float? = negPrimitive
println(posPrimitive == negPrimitive) //true
println(posBoxed == negBoxed) //true
println(posBoxed?.equals(negBoxed)) //false
karelpeeters
05/07/2019, 9:39 AMtrue, false, true
.Dias
05/07/2019, 9:39 AMprintln(posPrimitive.equals(negPrimitive)) //false
karelpeeters
05/07/2019, 9:40 AMFloat.equals
function, so according to the docs that makes sense.elect
05/07/2019, 9:41 AMkarelpeeters
05/07/2019, 9:42 AMkarelpeeters
05/07/2019, 9:44 AM