chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] (abs 2147483648) evaluates to negative number


From: John Cowan
Subject: Re: [Chicken-users] (abs 2147483648) evaluates to negative number
Date: Fri, 31 Jul 2009 11:20:47 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

Alejandro Forero Cuervo scripsit:

> In Chicken 3.4.0 linux-unix-gnu-x86-64 the expression (abs 2147483648)
> evaluates to -2147483648 in both csi and a compiled program (negative?
> and positive?, however, seem to work correctly).

The bug is still present in 4.1.1, and it's drastic:

#;1> (abs 2147483648)
-2147483648
#;2> (abs 2147483649)
2147483647
#;3> (abs 2147483650)
2147483646
#;4> (abs 4294967296)
0

> It evaluated correctly in a 32-bits build of the same version.

It works in 32-bit Chicken because 2147483648 (like every integer greater
than 1073741823) is a flonum.

> In the meantime, I'll put the following in my programs.  Other people
> may want to do the same:
> 
>   (when (negative? (abs 2147483648))
>     (set! abs
>       (lambda (x)
>         (if (negative? x)
>           (- x)
>           x))))

I'd just override the definition of abs to begin with.

-- 
John Cowan              address@hidden          http://www.ccil.org/~cowan
Any day you get all five woodpeckers is a good day.  --Elliotte Rusty Harold




reply via email to

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