From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: [PATCH] Add unboxed floating point comparison instructions.
Date: Wed, 21 Dec 2016 16:12:20 -0500 [thread overview]
Message-ID: <87vaud7zrf.fsf@netris.org> (raw)
In-Reply-To: <87mvfpumfi.fsf@pobox.com> (Andy Wingo's message of "Wed, 21 Dec 2016 20:11:45 +0100")
Andy Wingo <wingo@pobox.com> 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
next prev parent reply other threads:[~2016-12-21 21:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-14 1:47 [PATCH] Add unboxed floating point comparison instructions David Thompson
2016-12-14 14:51 ` Thompson, David
2016-12-21 19:11 ` Andy Wingo
2016-12-21 21:12 ` Mark H Weaver [this message]
2017-01-05 1:41 ` Thompson, David
2017-01-08 22:06 ` Andy Wingo
2017-01-09 1:09 ` Thompson, David
2017-01-09 21:23 ` Andy Wingo
2017-01-10 0:47 ` Thompson, David
2017-01-12 15:38 ` Thompson, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vaud7zrf.fsf@netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).