unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: lloda <lloda@sarc.name>
To: Tomas Volf <~@wolfsden.cz>
Cc: 74031@debbugs.gnu.org
Subject: bug#74031: [PATCH] srfi-64: Accept complex numbers in test-approximate.
Date: Sat, 26 Oct 2024 20:35:36 +0200	[thread overview]
Message-ID: <231BD3C0-36C3-4528-9124-7427B133E832@sarc.name> (raw)
In-Reply-To: <20241026161015.21049-1-~@wolfsden.cz>


Like I wrote in a separate message, I think test-approximate should check the https://en.wikipedia.org/wiki/Euclidean_distance :

(<= (magnitude (- expected value)) epsilon)

For real numbers, it means the same as the current test. It would also work for other types for which the user has defined - and magnitude, like vectors.

I just checked the old impl:

-(define (%test-approximate= error)
-  (lambda (value expected)
-    (let ((rval (real-part value))
-          (ival (imag-part value))
-          (rexp (real-part expected))
-          (iexp (imag-part expected)))
-      (and (>= rval (- rexp error))
-           (>= ival (- iexp error))
-           (<= rval (+ rexp error))
-           (<= ival (+ iexp error))))))

This is still *a* distance (https://en.wikipedia.org/wiki/Chebyshev_distance), and close numbers will be close either way, but speaking as an engineer who uses complex numbers all day, Euclidean distance is the only one I've ever wanted to use.

Regards

  lloda






  parent reply	other threads:[~2024-10-26 18:35 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 [this message]
2024-10-26 20:19 ` bug#74031: [PATCH v2] " Tomas Volf
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=231BD3C0-36C3-4528-9124-7427B133E832@sarc.name \
    --to=lloda@sarc.name \
    --cc=74031@debbugs.gnu.org \
    --cc=~@wolfsden.cz \
    /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).