summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 14:48:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 14:48:55 +0000
commit7c9a3d19fcacb57463d823d06f579129fa836820 (patch)
tree1acc384bb22a56911d15fd8b5bc17c9b976b92bb
parent0eab2b464e6861da0cc55f6dc1c7561e6628c74e (diff)
parse.y: calculate powers of ten
* parse.y (parser_yylex): calculate denominator directly as powers of ten, not parsing string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--internal.h3
-rw-r--r--numeric.c6
-rw-r--r--parse.y4
4 files changed, 14 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 93a4c08..ae0a75f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Fri Aug 2 23:14:54 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Aug 2 23:48:36 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (parser_yylex): calculate denominator directly as powers of
+ ten, not parsing string.
* parse.y (parser_number_literal_suffix): return bit set of found
suffixes.
diff --git a/internal.h b/internal.h
index 46d64b0..03acd3f 100644
--- a/internal.h
+++ b/internal.h
@@ -503,6 +503,9 @@ VALUE rb_big_sq_fast(VALUE x);
/* io.c */
void rb_maygvl_fd_fix_cloexec(int fd);
+/* numeric.c */
+VALUE rb_int_positive_pow(long x, unsigned long y);
+
/* process.c */
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen);
diff --git a/numeric.c b/numeric.c
index 05035b7..bdb0aaf 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2986,6 +2986,12 @@ int_pow(long x, unsigned long y)
return LONG2NUM(z);
}
+VALUE
+rb_int_positive_pow(long x, unsigned long y)
+{
+ return int_pow(x, y);
+}
+
/*
* call-seq:
* fix ** numeric -> numeric_result
diff --git a/parse.y b/parse.y
index e3c0caa..fa90c97 100644
--- a/parse.y
+++ b/parse.y
@@ -7649,9 +7649,7 @@ parser_yylex(struct parser_params *parser)
type = tRATIONAL;
memmove(point, point+1, fraclen+1);
v = rb_cstr_to_inum(tok(), 10, FALSE);
- *point = '1';
- memset(point+1, '0', fraclen);
- v = rb_rational_new(v, rb_cstr_to_inum(point, 10, FALSE));
+ v = rb_rational_new(v, rb_int_positive_pow(10, fraclen));
}
else {
double d = strtod(tok(), 0);