unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: guile-devel@gnu.org
Subject: Re: [PATCH] First batch of numerics changes
Date: Thu, 27 Jan 2011 17:06:19 -0500	[thread overview]
Message-ID: <87fwse3stg.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <87tygv4726.fsf@yeeloong.netris.org> (Mark H. Weaver's message of "Wed, 26 Jan 2011 17:46:25 -0500")

I'm having second thoughts about two of the patches:

* Patch 0010: `inf?' and `nan?' throw exceptions when applied to
  non-numbers

Previously, these predicates would return #f in that case.  I tend to
prefer strictness, but perhaps backward compatibility is more important
than strictness here.  What do you think?

* Patch 0018: Exact 0 times infinity or a NaN yields a NaN

Previously, exact 0 times anything yields exact 0.  This patch makes
exact 0 times any _finite_ number yield an exact 0, but makes exact 0
times an infinity or NaN yield a NaN.

This is a mistake.  A computation involving inexact arguments is
permitted to produce an exact answer only if the same answer would be
produced regardless of the value of the inexact arguments.

R6RS provides these examples, and gives us choices:

  (* 0 +inf.0) ==> 0 or +nan.0
  (* 0 +nan.0) ==> 0 or +nan.0
  (* 1.0 0)    ==> 0 or 0.0

But the choices are linked.  (* 0 n) may produce an exact 0 only if the
answer is exact 0 for _any_ value of n (including infinities or NaNs).

On the other hand, if we decide that the three cases above should return
an exact 0, then we are on mathematically questionable grounds.
Consider:

  (/ 0.0)       ==> +inf.0   (required by R6RS)
  (* 0 +inf.0)  ==> 0        (one of two choices, per R6RS)
  (* 0 (/ 0.0)) ==> 0
  (/ 0 0.0)     ==> +nan.0   (required by R6RS)

The inconsistency of the last two cases does not sit well with me,
but in order to eliminate this inconsistency, we must concede that
exact 0 times any inexact number must produce an inexact result.

I am leaning toward the following:

  (* 0 +inf.0) ==> +nan.0
  (* 0 +nan.0) ==> +nan.0
  (* 0 1.0)    ==> 1.0
  (* 0 0.0)    ==> 0.0

What do you think?

      Mark



  reply	other threads:[~2011-01-27 22:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26 16:32 [PATCH] First batch of numerics changes Mark H Weaver
2011-01-26 18:07 ` Mark H Weaver
2011-01-26 22:46 ` Mark H Weaver
2011-01-27 22:06   ` Mark H Weaver [this message]
2011-01-28 12:19     ` Andy Wingo
2011-01-29  0:05       ` Mark H Weaver
2011-01-29 11:29         ` Andy Wingo
2011-01-27 22:32   ` Mark H Weaver
2011-01-28 13:46   ` Andy Wingo
2011-01-28 14:44     ` Noah Lavine
2011-01-28 15:55       ` Andy Wingo
2011-01-29  8:20     ` Mark H Weaver
2011-01-29 17:42       ` Andy Wingo
2011-01-29 20:20         ` Mark H Weaver
2011-01-30 11:48           ` Andy Wingo
2011-01-29 17:50       ` Andy Wingo
2011-01-29 20:36         ` Mark H Weaver
2011-01-29 22:24         ` Mark H Weaver
2011-01-30  6:02           ` Commentary: R6RS div0-and-mod0 vs Taylor's `round/' Mark H Weaver
2011-01-30 11:50           ` [PATCH] First batch of numerics changes Andy Wingo
2011-01-30 12:12       ` Andy Wingo
2011-01-30 16:33         ` Mark H Weaver
2011-01-28 11:41 ` Andy Wingo
2011-01-28 23:36   ` Mark H Weaver

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=87fwse3stg.fsf@yeeloong.netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    /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).