unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: fix for expt bug
Date: Sat, 20 Nov 2010 22:49:46 +0100	[thread overview]
Message-ID: <m3zkt3zmv9.fsf@unquote.localdomain> (raw)
In-Reply-To: <87lj53r09h.fsf@gnu.org> ("Ludovic Courtès"'s message of "Mon, 08 Nov 2010 22:08:58 +0100")

Hi,

On Mon 08 Nov 2010 22:08, ludo@gnu.org (Ludovic Courtès) writes:

> Mark H Weaver <mhw@netris.org> writes:
>
>> No, (integer? 3.0) returns #t, as it should, according to R5RS.
>> R5RS's description of "integer?" gives this precise example, and
>> guile's implementation agrees.
>
> Damn, I had never realized that, shame on me.

Bill Schottstaedt has a nice rant on
https://ccrma.stanford.edu/software/snd/snd/s7.html. I think all of his
examples are taken from Guile...

    I can't find the right tone for this section; this is the 400-th
    revision; I wish I were a better writer! I think the exact/inexact
    distinction in Scheme is confused and useless, and leads to verbose
    and buggy code. In some Schemes, "rational" means "could possibly be
    expressed equally well as a ratio (floats are approximations)". In
    s7 it's: "is actually expressed as a ratio (or an integer of
    course)"; otherwise "rational?" is the same as "real?":

    (not-s7-scheme)> (rational? (sqrt 2))
    #t

    As I understand it, "inexact" originally meant "floating point", and
    "exact" meant integer or ratio of integers. But words have a life of
    their own. 0.0 somehow became an "inexact" integer (although it can
    be represented exactly in floating point). +inf.0 must be an integer
    — its fractional part is explicitly zero! But +nan.0... And then
    there's:

    (not-s7-scheme)> (integer? 9007199254740993.1)
    #t

    When does this matter? I often need to index into a vector, but the
    index is a float (a "real" in Scheme-speak: its fractional part can
    be non-zero). In one scheme:

    (not-s7-scheme)> (vector-ref #(0) (floor 0.1))
    ERROR: Wrong type (expecting exact integer): 0.0   ; [why?  "it's probably a programmer mistake"!]

    Not to worry, I'll use inexact->exact:

    (not-s7-scheme)> (inexact->exact 0.1)              ; [why? "floats are ratios"!]
    3602879701896397/36028797018963968

    So I end up using the verbose (floor (inexact->exact ...))
    everywhere, and even then I have no guarantee that I'll get a legal
    vector index. When I started work on s7, I thought perhaps "exact"
    could mean "is represented exactly in the computer". We'd have
    integers and ratios exact; reals and complex exact if they are
    exactly represented in the current floating point
    implementation. 0.0 and 0.5 might be exact if the printout isn't
    misleading, and 0.1 is inexact. "integer?" and friends would refer
    instead to the programmer's point of view. That is, if the
    programmer uses 1 or if the thing prints as 1, it is the integer 1,
    whereas 1.0 means floating point (not integer!). And to keep
    exactness in view, we'd have to monitor which operations introduce
    inexactness — a kind of interval arithmetic. But then what would
    inexact->exact do? If we discard the exact/inexact distinction, we
    can maintain backwards compatibility via:

        (define exact? rational?)
        (define (inexact? x) (not (rational? x)))
        (define inexact->exact rationalize) ; or floor
        (define (exact->inexact x) (* x 1.0))

There is also Mike Sperber's paper a few years ago about Scheme's
numeric tower being borked.

Anyway, just to say that you're in good company :)

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2010-11-20 21:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-31 18:12 fix for expt bug Ramakrishnan Muthukrishnan
2010-11-01  0:03 ` Mark H Weaver
2010-11-01  4:03   ` Ramakrishnan Muthukrishnan
2010-11-01 18:23     ` Ramakrishnan Muthukrishnan
2010-11-02  4:55       ` Mark H Weaver
2010-11-02  5:22         ` Ramakrishnan Muthukrishnan
2010-11-02  5:36           ` Ramakrishnan Muthukrishnan
2010-11-02 19:19             ` Mark H Weaver
2010-11-02 23:00             ` Ludovic Courtès
2010-11-03  2:10             ` Mark H Weaver
2010-11-03  9:41               ` Ramakrishnan Muthukrishnan
2010-11-03 15:32                 ` Mark H Weaver
2010-11-03 16:41                   ` Ramakrishnan Muthukrishnan
2010-11-03 16:22                 ` Mark H Weaver
2010-11-03 17:53                   ` Ramakrishnan Muthukrishnan
2010-11-03 18:25                     ` Ramakrishnan Muthukrishnan
2010-11-03 23:27                   ` Ludovic Courtès
2010-11-04 17:27                     ` Mark H Weaver
2010-11-08 21:08                       ` Ludovic Courtès
2010-11-20 21:49                         ` Andy Wingo [this message]
2010-11-21 22:34                           ` Ludovic Courtès
2010-11-05  2:18                     ` [PATCH] Fix bugs in expt and integer-expt Mark H Weaver
2010-11-10 22:01                       ` Ludovic Courtès
2011-01-20 22:47                       ` Andy Wingo

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=m3zkt3zmv9.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).