commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] branch master updated: Allow floating-point error in the log10 test.
Date Wed, 04 Dec 2019 19:01:02 GMT
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git


The following commit(s) were added to refs/heads/master by this push:
     new 3861867  Allow floating-point error in the log10 test.
3861867 is described below

commit 3861867532f3892fcf24c56a470fe59aa04681b0
Author: Alex Herbert <aherbert@apache.org>
AuthorDate: Wed Dec 4 19:00:56 2019 +0000

    Allow floating-point error in the log10 test.
---
 .../test/java/org/apache/commons/numbers/complex/ComplexTest.java  | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
index 6669e82..2711c61 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
@@ -1246,12 +1246,17 @@ public class ComplexTest {
 
     @Test
     public void testLog10() {
+        final double ln10 = Math.log(10);
         final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
         for (int i = 0; i < 10; i++) {
             final Complex z = Complex.ofCartesian(rng.nextDouble(), rng.nextDouble());
             final Complex lnz = z.log();
             final Complex log10z = z.log10();
-            Assertions.assertEquals(Math.log10(Math.exp(lnz.getReal())), log10z.getReal(),
"real");
+            // This is prone to floating-point error so use a delta
+            Assertions.assertEquals(lnz.getReal() / ln10, log10z.getReal(), 1e-12, "real");
+            // This test should be exact
+            final double abs = z.abs();
+            Assertions.assertEquals(Math.log10(abs), log10z.getReal(), "real");
             Assertions.assertEquals(lnz.getImaginary(), log10z.getImaginary(), "imag");
         }
     }


Mime
View raw message