From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: hypotenuse (was: Re: Adding a generic mathematical library) Date: Sun, 21 Jul 2024 17:44:47 +0300 Message-ID: <86wmleby8w.fsf@gnu.org> References: <8734o9sdig.fsf@posteo.net> <87wmllqq66.fsf@posteo.net> <87plrdqnhc.fsf@posteo.net> <87le21qldj.fsf_-_@posteo.net> <878qy1at52.fsf@dataswamp.org> <87plr6u8al.fsf_-_@dataswamp.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17609"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Emanuel Berg Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 21 16:45:10 2024 Return-path: Envelope-to: ged-emacs-devel@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 1sVXoE-0004P3-2S for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Jul 2024 16:45:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVXnx-00076m-TP; Sun, 21 Jul 2024 10:44:53 -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 1sVXnv-00076X-OT for emacs-devel@gnu.org; Sun, 21 Jul 2024 10:44:51 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVXnt-0007sb-OJ; Sun, 21 Jul 2024 10:44:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=GFXKdsFV2kop4NNbszl8jxSVa4kz33CmKt/QYc/Kvzg=; b=LjtysyKwpeZi Wq6p3+Tt7DXr9sMbSs8qYqUe5i1sKB9I32kfn3honbRDS4NjwmCnF13pNF8L3eybqS1i6trjKpcJ7 zzpsonSQuig0NHcnUzE6Hj4/JmDKE2L0FVWHSjYEc9mXkm/vSYZYrv5h1kdsfNbcYWXpHFyTU8wVM yGyWB/MvPojRKtVhHGcWtfINCeiQ3V6iPJ3vABywuTnNfsCg4KkyjalLGunPF0zW0bz0r+PtIrUA+ yvxAKz6Q+IeIH+BCCcO4Ytcm6OtjAYx/rdYxnvfrCRyZSwoBWdSNHhZcuxQxQvwcO/VAWCW6q8Io/ 66WLXInkb15VzD2o6N23ng==; In-Reply-To: <87plr6u8al.fsf_-_@dataswamp.org> (message from Emanuel Berg on Sun, 21 Jul 2024 16:30:26 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:321889 Archived-At: > From: Emanuel Berg > Date: Sun, 21 Jul 2024 16:30:26 +0200 > > Richard Stallman wrote: > > > Onsider, for instance, `hypotenuse'. The benefit of having > > that functoin would not quite be zero, but it would be > > small. Is it enough to justify the additional function name, > > and the complexity of documenting it? > > RMS has really performed excellently in this discussion and my > favorite part of his critique must be this. > > What a sharp eye, to immediately identify the problem of > a proposed solution! > > Indeed: Is it enough to justify the "complexity of documenting > it"? > > That is an excellent question, and I leave it free for all > to contemplate. Can we justify the complexity? You are mocking questions which happen to be serious and non-trivial to answer. > Or does the below two lines of Elisp belong to the dustbin > of computing? > > (defun hypotenuse (c1 c2) > (sqrt (+ (* c1 c1) (* c2 c2))) ) This is not the best way of computing hypot: squaring a number could overflow or underflow, and you get bad result. Try (hypotenuse 1.e-600 1.e-600) or (hypotenuse 1.e600 1.e600) and you will see it. Like I said: a high-quality math library needs to use solid algorithms that produce valid results whenever the problem has a solution. Stable and accurate algorithms for hypot are known, and the libm implementation usually follows it (and if it doesn't, we can roll our own).