[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#74031: [PATCH] srfi-64: Accept complex numbers in test-approximate.
From: |
lloda |
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