diff --git a/core-java-modules/core-java-numbers-5/src/main/java/com/baeldung/positivenegative/PositiveOrNegative.java b/core-java-modules/core-java-numbers-5/src/main/java/com/baeldung/positivenegative/PositiveOrNegative.java index a580aa5ac5..0fa32a0425 100644 --- a/core-java-modules/core-java-numbers-5/src/main/java/com/baeldung/positivenegative/PositiveOrNegative.java +++ b/core-java-modules/core-java-numbers-5/src/main/java/com/baeldung/positivenegative/PositiveOrNegative.java @@ -26,11 +26,11 @@ public class PositiveOrNegative { } public static Result bySignum(Float floatNumber) { - float result = Math.signum(floatNumber); + Float result = Math.signum(floatNumber); - if (result == 1.0f) { + if (result.compareTo(1.0f) == 0) { return Result.POSITIVE; - } else if (result == -1.0f) { + } else if (result.compareTo(-1.0f) == 0) { return Result.NEGATIVE; } return Result.ZERO; diff --git a/core-java-modules/core-java-numbers-5/src/test/java/com/baeldung/positivenegative/PositiveOrNegativeUnitTest.java b/core-java-modules/core-java-numbers-5/src/test/java/com/baeldung/positivenegative/PositiveOrNegativeUnitTest.java index 4807e8b928..847ef6edb6 100644 --- a/core-java-modules/core-java-numbers-5/src/test/java/com/baeldung/positivenegative/PositiveOrNegativeUnitTest.java +++ b/core-java-modules/core-java-numbers-5/src/test/java/com/baeldung/positivenegative/PositiveOrNegativeUnitTest.java @@ -1,10 +1,12 @@ package com.baeldung.positivenegative; -import org.junit.jupiter.api.Test; - -import static com.baeldung.positivenegative.PositiveOrNegative.Result.*; +import static com.baeldung.positivenegative.PositiveOrNegative.Result.NEGATIVE; +import static com.baeldung.positivenegative.PositiveOrNegative.Result.POSITIVE; +import static com.baeldung.positivenegative.PositiveOrNegative.Result.ZERO; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + class PositiveOrNegativeUnitTest { @Test void givenIntegers_whenChkPositiveOrNegativeByOperator_thenReturnExpectedResult() {