unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Tomas Volf <~@wolfsden.cz>
To: 74031@debbugs.gnu.org
Cc: Tomas Volf <~@wolfsden.cz>
Subject: bug#74031: [PATCH v2] srfi-64: Accept complex numbers in test-approximate.
Date: Sat, 26 Oct 2024 22:19:26 +0200	[thread overview]
Message-ID: <20241026202113.9329-1-~@wolfsden.cz> (raw)
In-Reply-To: <20241026161015.21049-1-~@wolfsden.cz>

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.
---
Require error to be real number and check using (checks notes) Chebyshev
distance.

 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..453296364 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 real parts are within @code{(real-part @var{error})}, and imaginary
+parts within @code{(imag-part @var{error})}.
+
 @end defspec")

 (define-syntax %test-error
--
2.46.0





  parent reply	other threads:[~2024-10-26 20:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-26 16:07 bug#74031: [PATCH] srfi-64: Accept complex numbers in test-approximate Tomas Volf
2024-10-26 17:22 ` Ludovic Courtès
2024-10-26 18:46   ` lloda
2024-10-26 20:26     ` Tomas Volf
2024-10-26 18:35 ` lloda
2024-10-26 20:19 ` Tomas Volf [this message]
2024-10-26 21:06 ` bug#74031: [PATCH v3] " Tomas Volf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20241026202113.9329-1-~@wolfsden.cz' \
    --to=~@wolfsden.cz \
    --cc=74031@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).