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

ruby-changes:32072

From: mrkn <ko1@a...>
Date: Fri, 13 Dec 2013 02:02:31 +0900 (JST)
Subject: [ruby-changes:32072] mrkn:r44151 (trunk): * ext/bigdecimal/bigdecimal.c (VPrint): be a static function, support another

mrkn	2013-12-13 02:02:20 +0900 (Fri, 13 Dec 2013)

  New Revision: 44151

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

  Log:
    * ext/bigdecimal/bigdecimal.c (VPrint): be a static function, support another
      dump formats, and add more information of the given bigdecimal.
    
    * ext/bigdecimal/bigdecimal.h: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/bigdecimal/bigdecimal.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44150)
+++ ChangeLog	(revision 44151)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 13 01:53:00 2013  Kenta Murata  <mrkn@m...>
+
+	* ext/bigdecimal/bigdecimal.c (VPrint): be a static function, support another
+	  dump formats, and add more information of the given bigdecimal.
+
+	* ext/bigdecimal/bigdecimal.h: ditto.
+
 Wed Dec 11 16:45:58 2013  Koichi Sasada  <ko1@a...>
 
 	* eval.c (rb_raise_jump): call c_return hook immediately after
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 44150)
+++ ext/bigdecimal/bigdecimal.c	(revision 44151)
@@ -126,6 +126,10 @@ static void  VpInternalRound(Real *c, si https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L126
 static int   VpLimitRound(Real *c, size_t ixDigit);
 static Real *VpCopy(Real *pv, Real const* const x);
 
+#ifdef BIGDECIMAL_ENABLE_VPRINT
+static int VPrint(FILE *fp,const char *cntl_chr,Real *a);
+#endif
+
 /*
  *  **** BigDecimal part ****
  */
@@ -4940,7 +4944,6 @@ Exit: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4944
     return (int)val;
 }
 
-#ifdef BIGDECIMAL_ENABLE_VPRINT
 /*
  *    cntl_chr ... ASCIIZ Character, print control characters
  *     Available control codes:
@@ -4951,10 +4954,11 @@ Exit: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4954
  *     Note: % must must not appear more than once
  *    a  ... VP variable to be printed
  */
-    VP_EXPORT int
+#ifdef BIGDECIMAL_ENABLE_VPRINT
+static int
 VPrint(FILE *fp, const char *cntl_chr, Real *a)
 {
-    size_t i, j, nc, nd, ZeroSup;
+    size_t i, j, nc, nd, ZeroSup, sep = 10;
     BDIGIT m, e, nn;
 
     /* Check if NaN & Inf. */
@@ -4989,6 +4993,16 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4993
 		    ++nc;
 		}
 		nc += fprintf(fp, "0.");
+		switch (*(cntl_chr + j + 1)) {
+		default:
+		    break;
+
+		case '0': case 'z':
+		    ZeroSup = 0;
+		    ++j;
+		    sep = cntl_chr[j] == 'z' ? RMPD_COMPONENT_FIGURES : 10;
+		    break;
+		}
 		for (i = 0; i < a->Prec; ++i) {
 		    m = BASE1;
 		    e = a->frac[i];
@@ -5001,7 +5015,7 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5015
 			    ++nd;
 			    ZeroSup = 0;    /* Set to print succeeding zeros */
 			}
-			if (nd >= 10) {    /* print ' ' after every 10 digits */
+			if (nd >= sep) {    /* print ' ' after every 10 digits */
 			    nd = 0;
 			    nc += fprintf(fp, " ");
 			}
@@ -5010,6 +5024,7 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5024
 		    }
 		}
 		nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
+		nc += fprintf(fp, " (%"PRIdVALUE", %lu, %lu)", a->exponent, a->Prec, a->MaxPrec);
 	    }
 	    else {
 		nc += fprintf(fp, "0.0");
@@ -5043,9 +5058,10 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5058
 	}
 	j++;
     }
+
     return (int)nc;
 }
-#endif /* BIGDECIMAL_ENABLE_VPRINT */
+#endif
 
 static void
 VpFormatSt(char *psz, size_t fFmt)
Index: ext/bigdecimal/bigdecimal.h
===================================================================
--- ext/bigdecimal/bigdecimal.h	(revision 44150)
+++ ext/bigdecimal/bigdecimal.h	(revision 44151)
@@ -310,7 +310,6 @@ VP_EXPORT Real *VpOne(void); https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.h#L310
 #define VpExponent(a)   (a->exponent)
 #ifdef BIGDECIMAL_DEBUG
 int VpVarCheck(Real * v);
-VP_EXPORT int VPrint(FILE *fp,const char *cntl_chr,Real *a);
 #endif /* BIGDECIMAL_DEBUG */
 
 #if defined(__cplusplus)

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

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