[前][次][番号順一覧][スレッド一覧]

ruby-changes:30282

From: nobu <ko1@a...>
Date: Fri, 2 Aug 2013 23:49:07 +0900 (JST)
Subject: [ruby-changes:30282] nobu:r42334 (trunk): parse.y: calculate powers of ten

nobu	2013-08-02 23:48:55 +0900 (Fri, 02 Aug 2013)

  New Revision: 42334

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42334

  Log:
    parse.y: calculate powers of ten
    
    * parse.y (parser_yylex): calculate denominator directly as powers of
      ten, not parsing string.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/numeric.c
    trunk/parse.y

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42333)
+++ ChangeLog	(revision 42334)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Aug  2 23:14:54 2013  Nobuyoshi Nakada  <nobu@r...>
+Fri Aug  2 23:48:36 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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.
Index: parse.y
===================================================================
--- parse.y	(revision 42333)
+++ parse.y	(revision 42334)
@@ -7649,9 +7649,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7649
 		    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);
Index: numeric.c
===================================================================
--- numeric.c	(revision 42333)
+++ numeric.c	(revision 42334)
@@ -2986,6 +2986,12 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2986
     return LONG2NUM(z);
 }
 
+VALUE
+rb_int_positive_pow(long x, unsigned long y)
+{
+    return int_pow(x, y);
+}
+
 /*
  *  call-seq:
  *    fix ** numeric  ->  numeric_result
Index: internal.h
===================================================================
--- internal.h	(revision 42333)
+++ internal.h	(revision 42334)
@@ -503,6 +503,9 @@ VALUE rb_big_sq_fast(VALUE x); https://github.com/ruby/ruby/blob/trunk/internal.h#L503
 /* 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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]