unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* rationalize returns inexact results.
@ 2008-07-24  5:15 Anye Li
  0 siblings, 0 replies; 4+ messages in thread
From: Anye Li @ 2008-07-24  5:15 UTC (permalink / raw)
  To: bug-guile

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

Hi,

I've noticed that rationalize returns inexact results in Guile 1.8.3 (my
apologies if this has already been fixed), e.g. (rationalize 0.333333 0.01)
returns 0.333333333333333, which is inexact.  This is contrary to the claim
made by (help rationalize).  Since Guile now supports exact rationals,
shouldn't it return an exact result, e.g. 1/3 for the example given above?

Thanks,

Anye Li

[-- Attachment #2: Type: text/html, Size: 456 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rationalize returns inexact results.
@ 2008-07-25 17:33 Bill Schottstaedt
  0 siblings, 0 replies; 4+ messages in thread
From: Bill Schottstaedt @ 2008-07-25 17:33 UTC (permalink / raw)
  To: bug-guile

> Since Guile now supports exact rationals, shouldn't it return an exact result?

I actually agree with you (I implemented rationalize in Guile, and originally
it always returned a ratio -- why else call it "rationalize"?), but Marius
pointed out that R5RS says "With the exception of inexact->exact, the 
operations described in this section must generally return inexact results
when given any inexact arguments" in the section including rationalize.
I doubt that R6RS fixed this bug.  So, to get an exact result you need to
give exact arguments:

guile> (rationalize (inexact->exact .33) 1/10)
1/3






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rationalize returns inexact results.
@ 2008-07-26  5:39 Anye Li
  2008-08-02 23:24 ` Neil Jerram
  0 siblings, 1 reply; 4+ messages in thread
From: Anye Li @ 2008-07-26  5:39 UTC (permalink / raw)
  To: bug-guile

Even if it is not a bug that rationalize returns inexact results 
(surprising and useless as they may be to me), I believe it is still a 
bug that (help rationalize) says "Return an exact number..." when in 
fact it does not.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rationalize returns inexact results.
  2008-07-26  5:39 rationalize returns inexact results Anye Li
@ 2008-08-02 23:24 ` Neil Jerram
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Jerram @ 2008-08-02 23:24 UTC (permalink / raw)
  To: Anye Li; +Cc: bug-guile

2008/7/26 Anye Li <li.anye.0@gmail.com>:
> Even if it is not a bug that rationalize returns inexact results (surprising
> and useless as they may be to me), I believe it is still a bug that (help
> rationalize) says "Return an exact number..." when in fact it does not.

Agreed.  I'm just fixing this now, to make (help rationalize) say the
same as the Guile manual says:

Returns the @emph{simplest} rational number differing
from @var{x} by no more than @var{eps}.

As required by @acronym{R5RS}, @code{rationalize} only returns an
exact result when both its arguments are exact.  Thus, you might need
to use @code{inexact->exact} on the arguments.

@lisp
(rationalize (inexact->exact 1.2) 1/100)
@result{} 6/5


Regards,
       Neil




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-02 23:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-26  5:39 rationalize returns inexact results Anye Li
2008-08-02 23:24 ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2008-07-25 17:33 Bill Schottstaedt
2008-07-24  5:15 Anye Li

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).