unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] First batch of numerics changes
Date: Sat, 29 Jan 2011 15:20:37 -0500	[thread overview]
Message-ID: <87k4hn31ii.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <m34o8r4ner.fsf@unquote.localdomain> (Andy Wingo's message of "Sat, 29 Jan 2011 18:42:20 +0100")

Andy Wingo <wingo@pobox.com> writes:
>>    if (SCM_CELL_TYPE (x) != SCM_CELL_TYPE (y))
>> +    return SCM_BOOL_F;
>
> Doesn't this prevent 1.0+0.0i from being eqv or equal to 1.0 ?

No, because 1.0+0.0i never exists in the current code.

At the top of numbers.c it says:
> /* General assumptions:
>  * All objects satisfying SCM_COMPLEXP() have a non-zero complex component.

and I have found this to be true.  scm_c_make_rectangular is the
primitive function that creates complex numbers, and it returns a real
number if the imaginary part is zero.  All other functions call it
directly or indirectly.

I know this well because I made a patch to allow the creation of complex
numbers with inexact 0.0 imaginary part.  In fact, I purposefully
arranged for (eqv? 1.0+0.0i) to evaluate to #f, for the same reason that
(eqv? 0.0 0) evaluates to #f.

According to R6RS, a number is real only if its imaginary part is both
zero and exact.  Therefore, the imaginary part of any real number is an
exact 0, otherwise it wouldn't be real.  But the imaginary part of
1.0+0.0i is clearly an _inexact_ zero.

R6RS explicitly states that eqv? returns #f if one number is exact and
the other is inexact.  So (eqv? 0.0 0) must be #f, and has been.  The
only remaining assumption here is that (eqv? z1 z2) works by comparing
the real and imaginary parts component-wise using eqv?.  If you agree
with this, then it follows that any complex number, even one with an
inexact zero imaginary part, must be unequal to _any_ real number.

However, regardless of whether or not you agree with all this, the fact
remains that currently, Guile never creates non-real complex numbers
with zero imaginary part.  So the patch is safe.

    Best,
     Mark



  reply	other threads:[~2011-01-29 20:20 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
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 [this message]
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=87k4hn31ii.fsf@yeeloong.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).