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: Toru TSUNEYOSHI
Subject: Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ?
Date: Sat, 24 Oct 2009 10:50:33 +0900

From: Eli Zaretskii <address@hidden>

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

(Regrettably, platform of machines I have is only 32-bit, and I don't
 know about 64-bit platforms.)

About string-to-number, it suppose that type of `i' to FIXNUM_OVERFLOW_P
is `double'.

  In string-to-number:

    {
      double v = 0;

      while (1)
        {
          int digit = digit_to_number (*p++, b);
          if (digit < 0)
            break;
          v = v * b + digit;
        }

      val = make_fixnum_or_float (sign * v); /* <= type of argument is `double' 
*/
    }

So in 64-bit platforms, casting `double' to `int' causes lack of
precision already (because a double does not have 64 bits in the
mantissa), doesn't it?

(BTW, I wonder how application `bc' deals with overflow.)




reply via email to

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