From: Toru TSUNEYOSHI <t_tuneyosi@hotmail.com>
To: eliz@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ?
Date: Sat, 24 Oct 2009 15:07:44 +0900 [thread overview]
Message-ID: <BLU0-SMTP46F306FD68CD92D0A48FD3E2BC0@phx.gbl> (raw)
In-Reply-To: <20091024.105033.100383844.t_tuneyosi@hotmail.com>
[-- Attachment #1: Type: Text/Plain, Size: 342 bytes --]
> 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?
So I make a patch for keep the precision.
It tries to deal with the number in type `int' possibly, otherwise it
deals with the number in type `double'.
Would you like to check it ?
[-- Attachment #2: data.c.diff --]
[-- Type: Text/X-Patch, Size: 1064 bytes --]
--- data.c.original 2009-06-21 13:38:14.000000000 +0900
+++ data.c 2009-10-24 14:31:43.356164300 +0900
@@ -22,6 +22,7 @@
#include <config.h>
#include <signal.h>
#include <stdio.h>
+#include <limits.h>
#include "lisp.h"
#include "puresize.h"
#include "character.h"
@@ -2392,17 +2393,42 @@
val = make_float (sign * atof (p));
else
{
- double v = 0;
+ unsigned char *old_p = p;
+ int v = 0;
+ int overflow = 0;
- while (1)
+ while (v >= 0)
{
int digit = digit_to_number (*p++, b);
if (digit < 0)
break;
+ if (v > INT_MAX / b)
+ {
+ overflow = 1;
+ break;
+ }
v = v * b + digit;
}
- val = make_fixnum_or_float (sign * v);
+ if (!overflow && v >= 0)
+ {
+ val = make_fixnum_or_float (sign * v);
+ }
+ else
+ {
+ double w = 0;
+ p = old_p;
+
+ while (1)
+ {
+ int digit = digit_to_number (*p++, b);
+ if (digit < 0)
+ break;
+ w = w * b + digit;
+ }
+
+ val = make_fixnum_or_float (sign * w);
+ }
}
return val;
next prev parent reply other threads:[~2009-10-24 6:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BLU0-SMTP46F306FD68CD92D0A48FD3E2BC0@phx.gbl \
--to=t_tuneyosi@hotmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.