mrubyを超漢字で動作させる
Révision | 83794d1cb8e6685ad77f90ec7411f535213f14b8 (tree) |
---|---|
l'heure | 2017-06-05 22:59:08 |
Auteur | ornse01 <ornse01@user...> |
Commiter | ornse01 |
remove floating value conversion.
@@ -83,22 +83,25 @@ fmt_u(uint32_t x, char *s) | ||
83 | 83 | return s; |
84 | 84 | } |
85 | 85 | |
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 | |
91 | 94 | #endif |
92 | 95 | |
93 | 96 | 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) | |
95 | 98 | { |
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 | |
98 | 101 | uint32_t *a, *d, *r, *z; |
99 | 102 | uint32_t i; |
100 | 103 | 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; | |
102 | 105 | const char *prefix="-0X+0X 0X-0x+0x 0x"; |
103 | 106 | int pl; |
104 | 107 | 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) | ||
122 | 125 | return MAX(w, 3+pl); |
123 | 126 | } |
124 | 127 | |
125 | - y = frexp((double)y, &e2) * 2; | |
128 | + y = frexp(y, &e2) * 2; | |
126 | 129 | if (y) e2--; |
127 | 130 | |
128 | 131 | if ((t|32)=='a') { |
129 | - long double round = 8.0; | |
132 | + mrb_float round = 8.0; | |
130 | 133 | int re; |
131 | 134 | |
132 | 135 | if (t&32) prefix += 9; |
133 | 136 | pl += 2; |
134 | 137 | |
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; | |
137 | 140 | |
138 | 141 | if (re) { |
139 | 142 | 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) | ||
181 | 184 | if (y) y *= 268435456.0, e2-=28; |
182 | 185 | |
183 | 186 | 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; | |
185 | 188 | |
186 | 189 | do { |
187 | 190 | *z = y; |
@@ -202,7 +205,7 @@ fmt_fp(struct fmt_args *f, long double y, int w, int p, int fl, int t) | ||
202 | 205 | } |
203 | 206 | while (e2<0) { |
204 | 207 | 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; | |
206 | 209 | for (d=a; d<z; d++) { |
207 | 210 | uint32_t rm = *d & ((1<<sh)-1); |
208 | 211 | *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) | ||
224 | 227 | if (j < 9*(z-r-1)) { |
225 | 228 | uint32_t x; |
226 | 229 | /* 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; | |
229 | 232 | j %= 9; |
230 | 233 | for (i=10, j++; j<9; i*=10, j++); |
231 | 234 | x = *d % i; |
232 | 235 | /* Are there any significant digits past j? */ |
233 | 236 | 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; | |
236 | 239 | if (*d/i & 1) round += 2; |
237 | 240 | if (x<i/2) small=0.5; |
238 | 241 | else if (x==i/2 && d+1==z) small=1.0; |