unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* ratio implementation
@ 2003-07-28 11:24 Bill Schottstaedt
  2003-07-28 12:08 ` Han-Wen Nienhuys
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Bill Schottstaedt @ 2003-07-28 11:24 UTC (permalink / raw)


There is an implementation of ratios for Guile (based on CVS version
of 27-Jul-03) at ccrma-ftp.stanford.edu:/pub/Lisp/gratio.tar.gz.
Rather than send a huge diff, I placed the new versions of the changed
files (all from the libguile directory) in the tarball along with
*.diff showing the changes.  I added numerator, denominator,
rationalize and ratio?, and at the C level scm_make_ratio and
scm_i_ratio2real (should it be scm_ratio2dbl?).  "ratio?" is needed
because "rational?" returns #t if passed a real -- there has to be
some way to distiguish a ratio from a real. An alternative would be to
make "rational?"  rational.

I don't know how the FSF/GPL copyright stuff works, but I did this
work on my own time, did not look at any other implementation, and
hereby donate the code to you.  I'd be happy to "sign the papers".

I use longs for the numerator and denominator, so if bignums are
encountered, I fallback on the old method using scm_divide.  I didn't
try to provide the standard set of C-level type conversions -- not
sure these are needed in this case. I decided to follow Common Lisp
and reduce ratios, and return an integer if the ratio denominator is 1
(or if the numerator is 0).  One ugly change is the SCM_NUMP macro in
numbers.h -- the original of this macro strikes me as a kludge; the
new version is worse.  A questionable change (I followed Dybvig's book
p 126): (/ 17) -> 1/17, (/ 2 3) -> 2/3.  I notice that r5rs seems to
imply that (inexact->exact .3) should return 3/10 (see the rationalize
example which is assuming this) -- should I implement this?  What is
"reasonably close" in this case?  Another gray area involves functions
like round -- in r5rs (round 7/2) returns 4, whereas Guile returns 4.0
(I left it this way because (round 7) currently returns 7.0 rather
than 7) -- I decided to make minimal changes, but handling of
exact/inexact distinctions in Guile could use some work (I am willing
do this, if others approve).  Also, should random accept ratios?
And currently (format #f "~F" 2/3) hangs, but so does
(format #f "~B" 1.5) (in Guile 1.6.4 you get an error, but
in the CVS Guile it hangs in mutex_lock).


The changed files are:

smob.c
hash.c
eq.c
goops.c
gc-card.c
objects.c
numbers.c (nearly all the changes are in this file)
eval.c

numbers.h
tags.h
objects.h

Also in the tarball: ratio-tests.scm.  




_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 36+ messages in thread
* fractions.test
@ 2004-01-17 13:40 Kevin Ryde
  2004-02-17 21:41 ` fractions.test Marius Vollmer
  0 siblings, 1 reply; 36+ messages in thread
From: Kevin Ryde @ 2004-01-17 13:40 UTC (permalink / raw)


Is test-suite/tests/fractions.test meant to be included in the
distribution?

Naturally if so it'll need to be in Makefile.am, and will need a
copyright notice.

The comment about the clisp borrowings being gpl is not really right.
It's not enough to be gpl'ed, the copyright holder needs to be
identified (is it the FSF already?).


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

end of thread, other threads:[~2004-02-18 19:34 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-28 11:24 ratio implementation Bill Schottstaedt
2003-07-28 12:08 ` Han-Wen Nienhuys
2003-07-29  0:41 ` Kevin Ryde
2003-07-29 11:57   ` Bill Schottstaedt
2003-07-30 22:42     ` Kevin Ryde
2003-09-15 10:35 ` Marius Vollmer
2003-09-15 16:19   ` Rob Browning
2003-09-15 22:06   ` Dirk Herrmann
2003-09-15 22:59     ` Kevin Ryde
2003-09-16 11:39     ` Bill Schottstaedt
2003-09-16 21:36       ` Rob Browning
2003-09-18 21:09       ` Dirk Herrmann
2003-10-07 15:26         ` Marius Vollmer
2003-10-13 10:58           ` Bill Schottstaedt
2003-10-14  8:57             ` Marius Vollmer
2004-02-18 14:25               ` fractions.test Bill Schottstaedt
2003-10-14 12:39             ` ratio implementation Marius Vollmer
2003-10-14 22:56               ` Kevin Ryde
2003-10-14 13:03             ` Marius Vollmer
2003-10-14 23:37               ` Kevin Ryde
2003-10-16 11:49                 ` Bill Schottstaedt
2003-10-17 10:09                 ` Marius Vollmer
2003-10-17 11:47                   ` Bill Schottstaedt
2003-10-17 15:04                   ` Rob Browning
2003-10-18  0:45                   ` Kevin Ryde
2003-10-15 12:57               ` Bill Schottstaedt
2003-10-17 10:20                 ` Marius Vollmer
2003-10-17 15:14                   ` Rob Browning
2003-10-17 15:42                     ` Marius Vollmer
2003-10-14 23:01             ` Kevin Ryde
2003-10-18  0:55               ` ash using shifts (was: ratio implementation) Kevin Ryde
2003-10-07 15:24       ` ratio implementation Marius Vollmer
  -- strict thread matches above, loose matches on Subject: below --
2004-01-17 13:40 fractions.test Kevin Ryde
2004-02-17 21:41 ` fractions.test Marius Vollmer
2004-02-17 23:29   ` fractions.test Kevin Ryde
2004-02-18 19:34     ` fractions.test Marius Vollmer

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