chicken-users
[Top][All Lists]

## 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
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

the numbers extension library, which adds support for arbitrary
precision arithmetic and exact fractions to CHICKEN:

\$ csi -n

[...]

#;1> (require-library numbers)
#;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
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

--