• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

mrubyを超漢字で動作させる


Commit MetaInfo

Révision83794d1cb8e6685ad77f90ec7411f535213f14b8 (tree)
l'heure2017-06-05 22:59:08
Auteurornse01 <ornse01@user...>
Commiterornse01

Message de Log

remove floating value conversion.

Change Summary

Modification

--- a/src/fmt_fp.c
+++ b/src/fmt_fp.c
@@ -83,22 +83,25 @@ fmt_u(uint32_t x, char *s)
8383 return s;
8484 }
8585
86-/* Do not override this check. The floating point printing code below
87- * depends on the float.h constants being right. If they are wrong, it
88- * may overflow the stack. */
89-#if LDBL_MANT_DIG == 53
90-//typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)];
86+#ifdef MRB_USE_FLOAT
87+# define MRB_FLOAT_MANT_DIG FLT_MANT_DIG
88+# define MRB_FLOAT_MAX_EXP FLT_MAX_EXP
89+# define MRB_FLOAT_EPSILON FLT_EPSILON
90+#else
91+# define MRB_FLOAT_MANT_DIG DBL_MANT_DIG
92+# define MRB_FLOAT_MAX_EXP DBL_MAX_EXP
93+# define MRB_FLOAT_EPSILON DBL_EPSILON
9194 #endif
9295
9396 static int
94-fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t)
97+fmt_fp(struct fmt_args *f, mrb_float y, int w, int p, int fl, int t)
9598 {
96- uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion
97- + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion
99+ uint32_t big[(MRB_FLOAT_MANT_DIG+28)/29 + 1 // mantissa expansion
100+ + (MRB_FLOAT_MAX_EXP+MRB_FLOAT_MANT_DIG+28+8)/9]; // exponent expansion
98101 uint32_t *a, *d, *r, *z;
99102 uint32_t i;
100103 int e2=0, e, j, l;
101- char buf[9+LDBL_MANT_DIG/4], *s;
104+ char buf[9+MRB_FLOAT_MANT_DIG/4], *s;
102105 const char *prefix="-0X+0X 0X-0x+0x 0x";
103106 int pl;
104107 char ebuf0[3*sizeof(int)], *ebuf=&ebuf0[3*sizeof(int)], *estr;
@@ -122,18 +125,18 @@ fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t)
122125 return MAX(w, 3+pl);
123126 }
124127
125- y = frexp((double)y, &e2) * 2;
128+ y = frexp(y, &e2) * 2;
126129 if (y) e2--;
127130
128131 if ((t|32)=='a') {
129- long double round = 8.0;
132+ mrb_float round = 8.0;
130133 int re;
131134
132135 if (t&32) prefix += 9;
133136 pl += 2;
134137
135- if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0;
136- else re=LDBL_MANT_DIG/4-1-p;
138+ if (p<0 || p>=MRB_FLOAT_MANT_DIG/4-1) re=0;
139+ else re=MRB_FLOAT_MANT_DIG/4-1-p;
137140
138141 if (re) {
139142 while (re--) round*=16;
@@ -181,7 +184,7 @@ fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t)
181184 if (y) y *= 268435456.0, e2-=28;
182185
183186 if (e2<0) a=r=z=big;
184- else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1;
187+ else a=r=z=big+sizeof(big)/sizeof(*big) - MRB_FLOAT_MANT_DIG - 1;
185188
186189 do {
187190 *z = y;
@@ -202,7 +205,7 @@ fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t)
202205 }
203206 while (e2<0) {
204207 uint32_t carry=0, *b;
205- int sh=MIN(9,-e2), need=1+(p+LDBL_MANT_DIG/3+8)/9;
208+ int sh=MIN(9,-e2), need=1+(p+MRB_FLOAT_MANT_DIG/3+8)/9;
206209 for (d=a; d<z; d++) {
207210 uint32_t rm = *d & ((1<<sh)-1);
208211 *d = (*d>>sh) + carry;
@@ -224,15 +227,15 @@ fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t)
224227 if (j < 9*(z-r-1)) {
225228 uint32_t x;
226229 /* We avoid C's broken division of negative numbers */
227- d = r + 1 + ((j+9*LDBL_MAX_EXP)/9 - LDBL_MAX_EXP);
228- j += 9*LDBL_MAX_EXP;
230+ d = r + 1 + ((j+9*MRB_FLOAT_MAX_EXP)/9 - MRB_FLOAT_MAX_EXP);
231+ j += 9*MRB_FLOAT_MAX_EXP;
229232 j %= 9;
230233 for (i=10, j++; j<9; i*=10, j++);
231234 x = *d % i;
232235 /* Are there any significant digits past j? */
233236 if (x || d+1!=z) {
234- long double round = 2/LDBL_EPSILON;
235- long double small;
237+ mrb_float round = 2/MRB_FLOAT_EPSILON;
238+ mrb_float small;
236239 if (*d/i & 1) round += 2;
237240 if (x<i/2) small=0.5;
238241 else if (x==i/2 && d+1==z) small=1.0;