Skip to content

Commit bfced1b

Browse files
shubhi22maibin
authored andcommitted
Bael 3404 strictfp in java (eugenp#8157)
* BAEL-3404 Creating new OOP module * BAEL-3404 Code changes
1 parent f55bc5d commit bfced1b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.strictfpUsage;
2+
3+
public strictfp interface Circle {
4+
double computeArea(double radius);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.strictfpUsage;
2+
3+
public strictfp class ScientificCalculator {
4+
5+
public double sum(double value1, double value2) {
6+
return value1 + value2;
7+
}
8+
9+
public double diff(double value1, double value2) {
10+
return value1 - value2;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.strictfpUsage;
2+
3+
import org.junit.Test;
4+
5+
import static org.hamcrest.Matchers.is;
6+
import static org.junit.Assert.assertThat;
7+
8+
public class ScientificCalculatorUnitTest {
9+
10+
@Test
11+
public void whenMethodOfstrictfpClassInvoked_thenIdenticalResultOnAllPlatforms() {
12+
ScientificCalculator calculator = new ScientificCalculator();
13+
double result = calculator.sum(23e10, 98e17);
14+
assertThat(result, is(9.800000230000001E18));
15+
result = calculator.diff(Double.MAX_VALUE, 1.56);
16+
assertThat(result, is(1.7976931348623157E308));
17+
}
18+
}

0 commit comments

Comments
 (0)