File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
core-java-modules/core-java-lang-oop-4/src
main/java/com/baeldung/strictfpUsage
test/java/com/baeldung/strictfpUsage Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .strictfpUsage ;
2
+
3
+ public strictfp interface Circle {
4
+ double computeArea (double radius );
5
+ }
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments