diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-02 14:48:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-02 14:48:55 +0000 |
commit | 7c9a3d19fcacb57463d823d06f579129fa836820 (patch) | |
tree | 1acc384bb22a56911d15fd8b5bc17c9b976b92bb | |
parent | 0eab2b464e6861da0cc55f6dc1c7561e6628c74e (diff) | |
download | ruby-7c9a3d19fcacb57463d823d06f579129fa836820.tar.gz |
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-- | ChangeLog | 5 | ||||
-rw-r--r-- | internal.h | 3 | ||||
-rw-r--r-- | numeric.c | 6 | ||||
-rw-r--r-- | parse.y | 4 |
4 files changed, 14 insertions, 4 deletions
@@ -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 46d64b00fc..03acd3f8e1 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); @@ -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 @@ -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); |