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

ruby-changes:35131

From: nobu <ko1@a...>
Date: Mon, 18 Aug 2014 17:06:51 +0900 (JST)
Subject: [ruby-changes:35131] nobu:r47213 (trunk): sprintf.c: remove magic numbers

nobu	2014-08-18 17:06:37 +0900 (Mon, 18 Aug 2014)

  New Revision: 47213

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

  Log:
    sprintf.c: remove magic numbers
    
    * sprintf.c (rb_str_format): name default float precision and
      remove unused initial value.

  Modified files:
    trunk/sprintf.c
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 47212)
+++ sprintf.c	(revision 47213)
@@ -455,6 +455,7 @@ rb_f_sprintf(int argc, const VALUE *argv https://github.com/ruby/ruby/blob/trunk/sprintf.c#L455
 VALUE
 rb_str_format(int argc, const VALUE *argv, VALUE fmt)
 {
+    enum {default_float_precision = 6};
     rb_encoding *enc;
     const char *p, *end;
     char *buf;
@@ -1030,7 +1031,7 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1031
 	    {
 		VALUE val = GETARG();
 		double fval;
-		int i, need = 6;
+		int i, need;
 		char fbuf[32];
 
 		fval = RFLOAT_VALUE(rb_Float(val));
@@ -1082,7 +1083,7 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1083
 		    if (i > 0)
 			need = BIT_DIGITS(i);
 		}
-		need += (flags&FPREC) ? prec : 6;
+		need += (flags&FPREC) ? prec : default_float_precision;
 		if ((flags&FWIDTH) && need < width)
 		    need = width;
 		need += 20;

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

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