emacs-devel
[Top][All Lists]
Advanced

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

Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ?


From: Eli Zaretskii
Subject: Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ?
Date: Fri, 23 Oct 2009 21:33:59 +0200

> Date: Sat, 24 Oct 2009 02:51:47 +0900
> From: Toru TSUNEYOSHI <address@hidden>
> 
>     /* Value is non-zero if C integer I doesn't fit into a Lisp fixnum.  */
> 
>     #define FIXNUM_OVERFLOW_P(i) \
>       ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
>        || (EMACS_INT) (i) < MOST_NEGATIVE_FIXNUM)
> 
> I think FIXNUM_OVERFLOW_P is problematic.
> 
> The reason is that
> in case `i' is 4294967296.0 (2^32), (EMACS_INT)(i) returns 0
> with a executable program by some compiler

This is a known problem, but I'm not sure what would be the right
solution.  FIXNUM_OVERFLOW_P fails like that for any unsigned integer
that is large enough, because EMACS_INT is a signed type, so large
unsigned values become small negative values, and pass the test.

> In conclusion, it needs casting to double, I think.
> 
>     #define FIXNUM_OVERFLOW_P(i) \
>       ((double)(i) > (double)MOST_POSITIVE_FIXNUM \
>        || (double)(i) < (double)MOST_NEGATIVE_FIXNUM)
> 
> What do you think about it ?

This will not work on 64-bit platforms (where EMACS_INT is a 64-bit
type), because a double does not have 64 bits in the mantissa, and so
you will lose significant digits by that cast.

An alternative would be to have a separate test for unsigned values.




reply via email to

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