From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add unboxed floating point comparison instructions. Date: Wed, 21 Dec 2016 16:12:20 -0500 Message-ID: <87vaud7zrf.fsf@netris.org> References: <87lgvjgu2s.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> <87mvfpumfi.fsf@pobox.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1482354785 4718 195.159.176.226 (21 Dec 2016 21:13:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Dec 2016 21:13:05 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: guile-devel To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Dec 21 22:13:01 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJoC4-0000dF-Sc for guile-devel@m.gmane.org; Wed, 21 Dec 2016 22:13:01 +0100 Original-Received: from localhost ([::1]:59193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJoC9-00042q-8j for guile-devel@m.gmane.org; Wed, 21 Dec 2016 16:13:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJoBu-0003uZ-0e for guile-devel@gnu.org; Wed, 21 Dec 2016 16:12:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cJoBq-0002Fg-LW for guile-devel@gnu.org; Wed, 21 Dec 2016 16:12:49 -0500 Original-Received: from world.peace.net ([50.252.239.5]:38074) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cJoBq-0002Cd-HQ for guile-devel@gnu.org; Wed, 21 Dec 2016 16:12:46 -0500 Original-Received: from pool-72-93-33-239.bstnma.east.verizon.net ([72.93.33.239] helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cJoBe-0007Ep-JI; Wed, 21 Dec 2016 16:12:34 -0500 In-Reply-To: <87mvfpumfi.fsf@pobox.com> (Andy Wingo's message of "Wed, 21 Dec 2016 20:11:45 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 50.252.239.5 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18807 Archived-At: Andy Wingo writes: > I think &min/0 should be replaced by (&min/f64). Probably also you need > a good +nan.0 story here; does this do the right thing? e.g. > > (let ((a +nan.0)) > (if (< a 100.0) > (< a 200.0) > (> a 50.0))) > > Does this fold to #t? I think for +nan.0 it should not, Right, any numerical comparison involving a NaN must return false. > but AFAIU with > your patch it does fold. (Guile has some optimizer problems related to > flonums, I think; this patch doesn't have to fix them all, but it > shouldn't make them worse, or if it does, we need a nice story.) > >> +(define-simple-type-checker (f64-< &f64 &f64)) >> +(define-f64-comparison-inferrer (f64-< < >=)) > > Likewise we need an understanding that the inverse of < is in fact >=. > Maybe it is indeed :) No, it is not, because of NaNs. What we can say is that (< x y) is equivalent to (> y x) and (<= x y) is equivalent to (>= y x). Also, inexact numerical operations are not associative. There's a lot more that could be said about this topic, but in general please be aware that the usual mathematical intuitions are a poor guide, and it is easy for a naive compiler to destroy the properties of carefully written numerical codes. Thanks, Mark