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: lloda <lloda <at> sarc.name>
To: Tomas Volf <~@wolfsden.cz>
Cc: 74031 <at> debbugs.gnu.org
Subject: bug#74031: [PATCH] srfi-64: Accept complex numbers in test-approximate.
Date: Sat, 26 Oct 2024 20:35:36 +0200
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





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.