diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-06-13 15:51:28 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-06-13 15:51:28 +0900 |
| commit | 38d2b7f84c938acab5aefba217474a9d033c0d07 (patch) | |
| tree | 8acd3489f613927086c584a213787dffff64e15b /src | |
| parent | db3d72a471a0ee4d8d6ea248e99b2b062b390511 (diff) | |
| download | mruby-38d2b7f84c938acab5aefba217474a9d033c0d07.tar.gz mruby-38d2b7f84c938acab5aefba217474a9d033c0d07.zip | |
float representation simplified
Diffstat (limited to 'src')
| -rw-r--r-- | src/numeric.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/src/numeric.c b/src/numeric.c index e894b3dc3..4285ca6bc 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -187,27 +187,13 @@ flo_to_s(mrb_state *mrb, mrb_value flt) { char buf[32]; mrb_float value = mrb_float(flt); - char *p, *e; if (isinf(value)) - return mrb_str_new2(mrb, value < 0 ? "-Infinity" : "Infinity"); + return mrb_str_new2(mrb, value < 0 ? "-inf" : "inf"); else if(isnan(value)) return mrb_str_new2(mrb, "NaN"); - sprintf(buf, "%#.15g", value); /* ensure to print decimal point */ - if (!(e = strchr(buf, 'e'))) { - e = buf + strlen(buf); - } - if (!ISDIGIT(e[-1])) { /* reformat if ended with decimal point (ex 111111111111111.) */ - sprintf(buf, "%#.14e", value); - if (!(e = strchr(buf, 'e'))) { - e = buf + strlen(buf); - } - } - p = e; - while (p[-1]=='0' && ISDIGIT(p[-2])) - p--; - memmove(p, e, strlen(e)+1); + sprintf(buf, "%.14g", value); return mrb_str_new2(mrb, buf); } |
