Bael 3404 strictfp in java (#8157)
* BAEL-3404 Creating new OOP module * BAEL-3404 Code changes
This commit is contained in:
parent
276e3cf94b
commit
906423af47
|
@ -0,0 +1,5 @@
|
||||||
|
package com.baeldung.strictfpUsage;
|
||||||
|
|
||||||
|
public strictfp interface Circle {
|
||||||
|
double computeArea(double radius);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue