diff --git a/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/Circle.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/Circle.java new file mode 100644 index 0000000000..a1f08d1bff --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/Circle.java @@ -0,0 +1,5 @@ +package com.baeldung.strictfpUsage; + +public strictfp interface Circle { + double computeArea(double radius); +} diff --git a/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/ScientificCalculator.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/ScientificCalculator.java new file mode 100644 index 0000000000..b898c3da3e --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/strictfpUsage/ScientificCalculator.java @@ -0,0 +1,12 @@ +package com.baeldung.strictfpUsage; + +public strictfp class ScientificCalculator { + + public double sum(double value1, double value2) { + return value1 + value2; + } + + public double diff(double value1, double value2) { + return value1 - value2; + } +} diff --git a/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/strictfpUsage/ScientificCalculatorUnitTest.java b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/strictfpUsage/ScientificCalculatorUnitTest.java new file mode 100644 index 0000000000..775c75ca9d --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/strictfpUsage/ScientificCalculatorUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.strictfpUsage; + +import org.junit.Test; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +public class ScientificCalculatorUnitTest { + + @Test + public void whenMethodOfstrictfpClassInvoked_thenIdenticalResultOnAllPlatforms() { + ScientificCalculator calculator = new ScientificCalculator(); + double result = calculator.sum(23e10, 98e17); + assertThat(result, is(9.800000230000001E18)); + result = calculator.diff(Double.MAX_VALUE, 1.56); + assertThat(result, is(1.7976931348623157E308)); + } +}