From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Volf <~@wolfsden.cz> Newsgroups: gmane.lisp.guile.bugs Subject: bug#74031: [PATCH] srfi-64: Accept complex numbers in test-approximate. Date: Sat, 26 Oct 2024 18:07:06 +0200 Message-ID: <20241026161015.21049-1-~@wolfsden.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9329"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Tomas Volf <~@wolfsden.cz> To: 74031@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat Oct 26 18:10:37 2024 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t4jN5-0002DX-Qh for guile-bugs@m.gmane-mx.org; Sat, 26 Oct 2024 18:10:36 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4jN1-00061J-CY; Sat, 26 Oct 2024 12:10:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4jMz-00060v-Gw for bug-guile@gnu.org; Sat, 26 Oct 2024 12:10:29 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t4jMz-0006Nm-2U for bug-guile@gnu.org; Sat, 26 Oct 2024 12:10:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=heIKgPLWLMJ9jMk/aKV4yJNIx53VUExjSksWWcDCCWU=; b=ReWdrGjIU35ouAIFSXY5CVxnu8wbQwLiYjXIcyfpAi0X1veKQSOalNck1TOk+JQmykz9Ts0tTJbR/kP4qXNJglt1+kxo/WMki40gN2Z7j1C0Egn4dsE+Kwy6K3XJCAJirQZc6TfFpRksMDBJyUHLkjsnXu+12laFp3w/GCwyLi/0tGPV2rQAK1Z4qyPl359TVbqHQdBfoFWvgAHB6gLZgY2o1Csayu9w8nRFyD/c0HNzSVLC6MkaBOWJ5nI8UC6snBDfqanrL2qUshNDlpRdWyJfEy5U84hmZ1xAvEDhw2E7FFh1F8rfpA9PvdQKbs+iJcJIaTK3hmbueNI8UghOfA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t4jNW-0005D5-HJ for bug-guile@gnu.org; Sat, 26 Oct 2024 12:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 26 Oct 2024 16:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74031 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172995906020017 (code B ref -1); Sat, 26 Oct 2024 16:11:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Oct 2024 16:11:00 +0000 Original-Received: from localhost ([127.0.0.1]:42354 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4jNT-0005Cn-QQ for submit@debbugs.gnu.org; Sat, 26 Oct 2024 12:11:00 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1t4jNQ-0005Cd-SW for submit@debbugs.gnu.org; Sat, 26 Oct 2024 12:10:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1t4jMs-00060P-Dx for bug-guile@gnu.org; Sat, 26 Oct 2024 12:10:22 -0400 Original-Received: from wolfsden.cz ([37.205.8.62]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1t4jMq-0006Je-7P for bug-guile@gnu.org; Sat, 26 Oct 2024 12:10:22 -0400 Original-Received: by wolfsden.cz (Postfix, from userid 104) id 1EFD93346DF; Sat, 26 Oct 2024 16:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1729959017; bh=O1F114eJ7v7MFRMTdIX5PqUuxypjO46l9VhNEvexM90=; h=From:To:Cc:Subject:Date; b=LTEIBFpguIY5/gWbdcigvzdNfRVO1Cmqm3B6vgvenh3OBvwwDjr4DCN7NdxIrUCKm eUl4s2OEK1DHG683NiKXewnUmgThSo2w8DljSy2jZjc16Q2AK5ym+nYt0c/RGFGtoB mkmeE1qNqE0dLJxzadzEUuKy4XIOqj+IU+G9IB60Kmp7OlD6dFFWNNXts8Rc1Fmue+ u/s/Y07MRHaMpLR6nOVD7PBuc2/Mng4hFFjoOqkwh2xFSpiw6SJL9SM/4cUFIPN6J2 YMZ9a9cRNiUJFo4RIW6nzyuabGApiSZ9DkEc8t5D6lan+W2F7elELHdFWNaagcGbXh fL5VkSx9bB1l9ys1i1u8ajxZ4iRcK/G4QM4kkUVhaHpMyfR1/1FPgIK5O4QEE4Dwih pPpoVRFDIEpw1qsFHf//uMVp0FLuioFPkHoK9SN9IHMIrWI52sw0qyf5ti9h7c1Xy/ UdUjmNa1ROq9jHSBMKDDajEcQaYOauG1FcJoTY3b19koPup4Usxfio7dBrhYrBTNwh Tn1u/E4bdticxE/XYvIIL9H2v27vjTjuOxem/bE2hR37hdEfouWSPMF/k4px5XntEO x5faOTuaSK3JkX0CGFk1JmPbjWT9JsiEFsrxoKyXH4Cux+3AFx1gLRHg3Yrrz91H4w a0fdzzRTgb7Kp9MGyfh+YJHY= Original-Received: from localhost (unknown [128.0.188.242]) by wolfsden.cz (Postfix) with ESMTPSA id AE785332068; Sat, 26 Oct 2024 16:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1729959016; bh=O1F114eJ7v7MFRMTdIX5PqUuxypjO46l9VhNEvexM90=; h=From:To:Cc:Subject:Date; b=OX7czHiNHEKsjMQA4qkR71XVwa2ByOu8cxA7TwKfkaqPDV3vhNB9hbTZlVPRkEr2r K4xw96SPN4hTe2qv6vOC669FAWdnVxADPmzAuQqfdFFCHpiUzhw0aWG3EoCYVmKyI8 gvPX+TeIa7i57JhgHmzSi9dBXQdfzcVUabGugsXPs2tJ16yhe6/SJiVXyENLdjUz4V PqyRPVoZ3ce7jTImQ+1SCLLhfvh0BqqBltlSucl4fL9w6Wlb7Mpt7ermkzVFWBhIuw SDdtGC9yYAMzUOANR5ixqZv41EjsMRcxAmE7Lw8IIuARfNDqBRidZ4YxJteMwoldX1 Lei8vc0qCgJtZaEtNt82tD4xaHJal4HqkJZ9KhHNo00WnPeZXOcVlgfUju+CgDzTiq 4SAvBnfJFuSp4uexmYG2j9JxZ7lCxtzgsaAdljWSAoTfKHBdLqysdFKFRFWX9sStIS yBEOKdrK8Pt16GFbk6TDgPhuiB28Uz92ibtUBbUbJf8jYwUPTTb8tpSCBnJ0C68Kop djmq6/37nUBPj/vgzPozY9MCLytoDcyQRtZV7xUdandwwSCP1avunvw+KmVH+l1xNJ d2fVbsNEgVKGR0LrSvlu12QnSqzeKTeOp6n8MP8Bqx58y6Xrzj7arMzpQYf4SO6Fz/ WXnOVtRZ8o27lhqvmkK+8mOY= X-Mailer: git-send-email 2.46.0 Received-SPF: pass client-ip=37.205.8.62; envelope-from=~@wolfsden.cz; helo=wolfsden.cz X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:11076 Archived-At: 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. --- Proposal for how to extend test-approximate to handle complex arguments. However it differs from the original one. That one expected `error' to be a real number, and used it for comparing both real parts and imaginary parts. To me, that seems weird. I would consider it useful to be able to have different errors for real and imaginary parts. However I cannot remember the last time I have used complex numbers, so I am not sure I am qualified to have an opinion here. What do other people think? module/srfi/srfi-64.scm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/module/srfi/srfi-64.scm b/module/srfi/srfi-64.scm index 1f60a72e5..5fc23e28a 100644 --- a/module/srfi/srfi-64.scm +++ b/module/srfi/srfi-64.scm @@ -776,8 +776,16 @@ 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)) + (ε-r (real-part ε)) + (ε-i (imag-part ε))) + (and (>= a-r (- e-r ε-r)) + (<= a-r (+ e-r ε-r)) + (>= a-i (- e-i ε-i)) + (<= a-i (+ e-i ε-i)))))) (define-syntax %test-approximate (λ (x) @@ -808,6 +816,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