unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* macro FIXNUM_OVERFLOW_P in lisp.h is valid ?
@ 2009-10-23 17:51 Toru TSUNEYOSHI
  2009-10-23 19:33 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Toru TSUNEYOSHI @ 2009-10-23 17:51 UTC (permalink / raw)
  To: emacs-devel

Hello.

I read the code of function `string-to-number', and traced functions or
macros recursively.

  traces of string-to-number:

    data.c: Fstring_to_number
      lisp.h: make_fixnum_or_float
        lisp.h: FIXNUM_OVERFLOW_P

  citation of FIXNUM_OVERFLOW_P (in Emacs 23.1):

    /* 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
(for example, Microsoft 32-bit C/C++ Compiler).
As a result, FIXNUM_OVERFLOW_P(i) returns 0.

  In Microsoft 32-bit C/C++ Compiler:

    i					(int)(i)
    ===============================================
    2147483648.0	(2^31)		-2147483648
    2147483647.0	(2^31 - 1)	 2147483647

    4294967296.0	(2^32)		 0
    4294967295.0	(2^32 - 1)	-1

    8589934592.0	(2^33)		 0
    8589934591.0	(2^33 - 1)	 -1

  In gcc version 3.4.4 (cygming special):

    i					(int)(i)
    ===============================================
    2147483648.0	(2^31)		-2147483648
    2147483647.0	(2^31 - 1)	 2147483647

    4294967296.0	(2^32)		-2147483648
    4294967295.0	(2^32 - 1)	-2147483648

    8589934592.0	(2^33)		-2147483648
    8589934591.0	(2^33 - 1)	-2147483648

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 ?




^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2009-10-26 14:48 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-23 17:51 macro FIXNUM_OVERFLOW_P in lisp.h is valid ? Toru TSUNEYOSHI
2009-10-23 19:33 ` Eli Zaretskii
2009-10-24  1:50   ` Toru TSUNEYOSHI
2009-10-24  9:05     ` Eli Zaretskii
2009-10-24 11:59       ` Toru TSUNEYOSHI
2009-10-24 13:00         ` Eli Zaretskii
2009-10-24 18:45           ` Toru TSUNEYOSHI
2009-10-24 15:14         ` Andreas Schwab
2009-10-24 18:39           ` Stefan Monnier
2009-10-26 14:48           ` Toru TSUNEYOSHI
     [not found]   ` <20091024.105033.100383844.t_tuneyosi@hotmail.com>
2009-10-24  6:07     ` Toru TSUNEYOSHI
     [not found]     ` <20091024.150744.186061320.t_tuneyosi@hotmail.com>
2009-10-24  7:46       ` Toru TSUNEYOSHI
2009-10-24 10:11         ` Eli Zaretskii
2009-10-23 20:57 ` Andreas Schwab
2009-10-23 22:02   ` Eli Zaretskii
2009-10-24  1:05     ` Stefan Monnier
2009-10-24  9:15       ` Eli Zaretskii
2009-10-24  9:40         ` Andreas Schwab
2009-10-24 10:16           ` Eli Zaretskii
2009-10-24 10:01         ` Andreas Schwab
2009-10-23 21:14 ` Stefan Monnier
2009-10-25  8:51   ` Toru TSUNEYOSHI
     [not found]   ` <20091025.175131.55657724.t_tuneyosi@hotmail.com>
2009-10-25 11:30     ` Toru TSUNEYOSHI

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).