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: Sat, 24 Oct 2009 15:00:03 +0200

> Date: Sat, 24 Oct 2009 20:59:47 +0900
> Cc: address@hidden
> From: Toru TSUNEYOSHI <address@hidden>
> 
> BTW, how does Emacs on 64-bit platforms eval the following expressions?
> 
>     (string-to-number "1152921504606846975") ; 2^60 - 1
>     =>                1.1529215046068467e+018 ; on 32-bit platforms
> 
> On 64-bit platforms, string-to-number should return the number as type
> `EMACS_INT' (= `LONG'), I think.

Yes, it should.

> Although, the code of string-to-number (Fstring_to_number) deals with
> the number as type `double' (of variable `v').

Yes, it does.  And thus it loses least significant digits:

  (string-to-number "1152921504606846975") => 1152921504606846720

>     #define make_fixnum_or_float(val) \
>        (FIXNUM_OVERFLOW_P (val) \
>         ? make_float (val) \
>         : make_number ((EMACS_INT)(val)))
> 
> In this code, FIXNUM_OVERFLOW_P (val) will returns 0.
> Then Emacs processes `make_number ((EMACS_INT)(val)))'.
> On that time, `val' is casted from type `double' to `EMACS_INT'.
> At last, can string-to-number return all digits of the number
> 1152921504606846975 properly?
> 
> I guessed it can't.
> That is the reason why I made my former patch.

OK, but please make your patch compare against MOST_POSITIVE_FIXNUM,
instead of using INT_MAX or LONG_MAX.  Also, if you know that the
value does not overflow an EMACS_INT, you can simply call make_number,
instead of make_fixnum_or_float.




reply via email to

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