chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Problems with rationals


From: Thomas Chust
Subject: Re: [Chicken-users] Problems with rationals
Date: Mon, 09 Apr 2012 22:13:21 +0200

On Mon, 2012-04-09 at 21:00 +0100, Mark Carter wrote:
> Is this a bug in chicken?
>       (rational? 6/10) => #f
> 
> Also
>       (* 1.0 5/2)
> produces
> Error: (*) bad argument type: 5/2
> [...]

Hello,

this looks strange. While CHICKEN does not support exact fractions out
of the box, reading a number in fractional notation should simply issue
a warning and return a floating point number. Also, when I apply the
rational? predicate from CHICKEN's core library to a floating point
number I get the answer #t:

$ csi -n

CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.4 (rev ad149e7)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2012-02-07 on hd-t1179cl (Linux)

#;1> (rational? 5/2)

Warning: cannot represent exact fraction - coerced to flonum: "5/2"
#t
#;2> (* 1.0 5/2)

Warning: cannot represent exact fraction - coerced to flonum: "5/2"
2.5

One way I can reproduce your problems is by loading but not importing
the numbers extension library, which adds support for arbitrary
precision arithmetic and exact fractions to CHICKEN:

$ csi -n

[...]

#;1> (require-library numbers)
; loading /usr/lib/chicken/6/numbers.so ...
#;2> (rational? 5/2)
#f
#;3> (* 1.0 5/2)

Error: (*) bad argument type: 5/2

        Call history:

        <syntax>          (* 1.0 5/2)
        <eval>    (* 1.0 5/2)   <--

This, however, is a misuse of the numbers library. The problem here is
that by loading the library the standard reader of CHICKEN is modified.
The fractional number notation then produces objects not understood by
CHICKEN's core libraries and to work with them you also have to import
the versions of arithmetic operators and numerical predicates that are
provided by the numbers library.

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]