unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* HEAD has now exact fractions
@ 2003-11-18 22:14 Marius Vollmer
  2003-11-18 22:23 ` Neil Jerram
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Marius Vollmer @ 2003-11-18 22:14 UTC (permalink / raw)


Hi,

I have committed the exact fraction support from Bill Schottstaedt.
Thanks alot Bill!

Please give it a beating and report all things you notice.

I have changed Bill's original code to varying degrees, so don't blame
him for anything that looks wrong.


Here are the relevant NEWS entries:

** Guile now has exact rationals.
 
Guile can now represent fractions such as 1/3 exactly.  Computing with
them is also done exactly, of course:
 
    (* 1/3 3/2)
    => 1/2
 
** 'floor', 'ceiling', 'round' and 'truncate' now return exact numbers
   for exact arguments.
 
For example: (floor 2) now returns an exact 2 where in the past it
returned an inexact 2.0.  Likewise, (floor 5/4) returns an exact 1.
 
** inexact->exact no longer returns only integers.
 
Without exact rationals, the closest exact number was always an
integer, but now inexact->exact returns the fraction that is exactly
equal to a floating point number.  For example:
 
    (inexact->exact 1.234)
    => 694680242521899/562949953421312
 
When you want the old behavior, use 'round' explicitely:
 
    (inexact->exact (round 1.234))
    => 1
 
** New function 'rationalize'.
 
This function finds a simple fraction that is close to a given real
number.  For example (and compare with inexact->exact above):
 
    (rationalize 1.234 0.0005)
    => 58/47
 
** 'odd?' and 'even?' work also for inexact integers.
 
Previously, (odd? 1.0) would signal an error since only exact integers
were recognized as integers.  Now (odd? 1.0) returns #t, (odd? 2.0)
returns #f and (odd? 1.5) signals an error.
 


-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


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


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

* Re: HEAD has now exact fractions
  2003-11-18 22:14 HEAD has now exact fractions Marius Vollmer
@ 2003-11-18 22:23 ` Neil Jerram
  2003-11-18 22:54 ` Kevin Ryde
  2003-11-19  2:03 ` Neil Jerram
  2 siblings, 0 replies; 7+ messages in thread
From: Neil Jerram @ 2003-11-18 22:23 UTC (permalink / raw)
  Cc: guile-devel

>>>>> "Marius" == Marius Vollmer <mvo@zagadka.de> writes:

    Marius> Hi, I have committed the exact fraction support from Bill
    Marius> Schottstaedt.  Thanks alot Bill!

Very cool.  Thank you Bill and Marius!

        Neil




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


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

* Re: HEAD has now exact fractions
  2003-11-18 22:14 HEAD has now exact fractions Marius Vollmer
  2003-11-18 22:23 ` Neil Jerram
@ 2003-11-18 22:54 ` Kevin Ryde
  2003-11-19  0:05   ` Marius Vollmer
  2003-11-19  2:03 ` Neil Jerram
  2 siblings, 1 reply; 7+ messages in thread
From: Kevin Ryde @ 2003-11-18 22:54 UTC (permalink / raw)


Marius Vollmer <mvo@zagadka.de> writes:
>
>     (inexact->exact 1.234)

You might like to show for instance 1.375 there, something that has an
exact binary representation.


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


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

* Re: HEAD has now exact fractions
  2003-11-18 22:54 ` Kevin Ryde
@ 2003-11-19  0:05   ` Marius Vollmer
  2003-11-19  0:59     ` Kevin Ryde
  0 siblings, 1 reply; 7+ messages in thread
From: Marius Vollmer @ 2003-11-19  0:05 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <mvo@zagadka.de> writes:
>>
>>     (inexact->exact 1.234)
>
> You might like to show for instance 1.375 there, something that has an
> exact binary representation.

Hmm, isn't that part of the point that 1.234 is indeed not exactly
representable and that the result of (inexact->exact 1.234) is not
something simple like 617/500?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


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


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

* Re: HEAD has now exact fractions
  2003-11-19  0:05   ` Marius Vollmer
@ 2003-11-19  0:59     ` Kevin Ryde
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Ryde @ 2003-11-19  0:59 UTC (permalink / raw)


Marius Vollmer <mvo@zagadka.de> writes:
>
> Hmm, isn't that part of the point that 1.234 is indeed not exactly
> representable and that the result of (inexact->exact 1.234) is not
> something simple like 617/500?

Yes, though 1.234 is subject to truncation when it's read.  I was just
thinking to avoid any uncertainty that might introduce.


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


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

* Re: HEAD has now exact fractions
  2003-11-18 22:14 HEAD has now exact fractions Marius Vollmer
  2003-11-18 22:23 ` Neil Jerram
  2003-11-18 22:54 ` Kevin Ryde
@ 2003-11-19  2:03 ` Neil Jerram
  2003-11-19  4:33   ` Marius Vollmer
  2 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2003-11-19  2:03 UTC (permalink / raw)
  Cc: guile-devel

>>>>> "Marius" == Marius Vollmer <mvo@zagadka.de> writes:

    Marius> Hi,
    Marius> I have committed the exact fraction support from Bill Schottstaedt.

I'm getting a compile error:

numbers.c: In function `scm_make_ratio':
numbers.c:395: parse error before `int'
numbers.c:397: `divisible_p' undeclared (first use in this function)
numbers.c:397: (Each undeclared identifier is reported only once
numbers.c:397: for each function it appears in.)

I'd guess the fix is just to declare divisible_p at the start of the
block, but I haven't looked closely.

        Neil



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


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

* Re: HEAD has now exact fractions
  2003-11-19  2:03 ` Neil Jerram
@ 2003-11-19  4:33   ` Marius Vollmer
  0 siblings, 0 replies; 7+ messages in thread
From: Marius Vollmer @ 2003-11-19  4:33 UTC (permalink / raw)
  Cc: guile-devel

Neil Jerram <neil@ossau.uklinux.net> writes:

> I'm getting a compile error:
>
> numbers.c: In function `scm_make_ratio':
> numbers.c:395: parse error before `int'

Right, I've fixed this by avoidin divisible_p completely.  Please
update.  Thanks!

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


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


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

end of thread, other threads:[~2003-11-19  4:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-18 22:14 HEAD has now exact fractions Marius Vollmer
2003-11-18 22:23 ` Neil Jerram
2003-11-18 22:54 ` Kevin Ryde
2003-11-19  0:05   ` Marius Vollmer
2003-11-19  0:59     ` Kevin Ryde
2003-11-19  2:03 ` Neil Jerram
2003-11-19  4:33   ` 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).