GNU bug report logs - #74031
[PATCH] srfi-64: Accept complex numbers in test-approximate.

Previous Next

Package: guile;

Reported by: Tomas Volf <~@wolfsden.cz>

Date: Sat, 26 Oct 2024 16:11:02 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Tomas Volf <~@wolfsden.cz>
To: 74031 <at> debbugs.gnu.org
Cc: Tomas Volf <~@wolfsden.cz>
Subject: bug#74031: [PATCH v3] srfi-64: Accept complex numbers in test-approximate.
Date: Sat, 26 Oct 2024 23:06:09 +0200
The specification mandates reals, but the reference implementation
supports complex numbers.  So as implementation extension, support them
as well.

* module/srfi/srfi-64.scm (within-epsilon): Support complex arguments.
---
v2: Use the same test logic as the reference implementation.
v3: Also adjust the docstring.

 module/srfi/srfi-64.scm | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/module/srfi/srfi-64.scm b/module/srfi/srfi-64.scm
index 1f60a72e5..0f1b5c117 100644
--- a/module/srfi/srfi-64.scm
+++ b/module/srfi/srfi-64.scm
@@ -776,8 +776,14 @@ Test whether result of @var{test-expr} matches @var{expected} using

 (define (within-epsilon ε)
   (λ (expected actual)
-    (and (>= actual (- expected ε))
-         (<= actual (+ expected ε)))))
+    (let ((e-r (real-part expected))
+          (e-i (imag-part expected))
+          (a-r (real-part actual))
+          (a-i (imag-part actual)))
+      (and (>= a-r (- e-r ε))
+           (<= a-r (+ e-r ε))
+           (>= a-i (- e-i ε))
+           (<= a-i (+ e-i ε))))))

 (define-syntax %test-approximate
   (λ (x)
@@ -808,6 +814,10 @@ Test whether result of @var{test-expr} matches @var{expected} using
 Test whether result of @var{test-expr} is within @var{error} of
 @var{expected}.

+As implementation extension, complex numbers are supported as well.  It tests
+whether both real and imaginary parts of @var{test-expr} are within
+@var{error} of real and imaginary parts of @var{expected}.
+
 @end defspec")

 (define-syntax %test-error
--
2.46.0




This bug report was last modified 233 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.