From 2387597f8183a6052e5ee9755f4932b7b911e3e7 Mon Sep 17 00:00:00 2001 From: Martin Tzvetanov Grigorov Date: Wed, 27 Jul 2022 14:54:49 +0300 Subject: [PATCH] Use StrictMath to get same results on different CPU architectures Related-to: #592 Maybe-related-to: https://bugs.openjdk.org/browse/JDK-8210416 Signed-off-by: Martin Tzvetanov Grigorov --- src/main/java/au/edu/wehi/idsv/util/MathUtil.java | 4 ++-- src/test/java/au/edu/wehi/idsv/util/MathUtilTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/au/edu/wehi/idsv/util/MathUtil.java b/src/main/java/au/edu/wehi/idsv/util/MathUtil.java index 1a5ab4d2b..31dbeddc9 100644 --- a/src/main/java/au/edu/wehi/idsv/util/MathUtil.java +++ b/src/main/java/au/edu/wehi/idsv/util/MathUtil.java @@ -2,11 +2,11 @@ public class MathUtil { public static double phredToPr(double phred) { - return Math.pow(10, -phred / 10); + return StrictMath.pow(10, -phred / 10); } public static double prToPhred(double pr) { if (pr == 0) return 0; - return -10 * Math.log10(pr); + return -10 * StrictMath.log10(pr); } /** * Returns the phred-scaled error probability of no diff --git a/src/test/java/au/edu/wehi/idsv/util/MathUtilTest.java b/src/test/java/au/edu/wehi/idsv/util/MathUtilTest.java index e4bcde62a..a80bfccad 100644 --- a/src/test/java/au/edu/wehi/idsv/util/MathUtilTest.java +++ b/src/test/java/au/edu/wehi/idsv/util/MathUtilTest.java @@ -13,7 +13,7 @@ public void phredOr_should_be_exact_for_single_score() { @Test public void phredOr_should_minimise_error() { // http://www.wolframalpha.com/input/?i=-10+*+%28log%2810%2C+1+-+%281+-+10%5E%28-5%2F10%29%29+*+%281+-+10%5E%28-5%2F10%29%29%29+%29 - assertEquals(2.737166564315747414571566754814524996985593328024647081266066, MathUtil.phredOr(5, 5), 0); + assertEquals(2.737166564315747, MathUtil.phredOr(5, 5), 0); assertEquals(4.999906094489629897297010515927232501782840270893945897373360, MathUtil.phredOr(5, 50), 0); assertEquals(0.999998875501369913289357102130159464124571763746365284402279, MathUtil.phredOr(1, 60), 0); assertEquals(0.99999999988755012243472182763604174153706462136143019889429, MathUtil.phredOr(1, 100), 0.000000000000001);