fmt_fp.c: move mruby specific `mrb_float_to_str` to `numeric.c`

parent 05cc3a8d
...@@ -361,28 +361,4 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch ...@@ -361,28 +361,4 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch
return s - buf; return s - buf;
} }
MRB_API mrb_value
mrb_float_to_str(mrb_state *mrb, mrb_value flo)
{
char buf[25];
#ifdef MRB_USE_FLOAT32
const int prec = 7;
#else
const int prec = 15;
#endif
mrb_format_float(mrb_float(flo), buf, sizeof(buf), 'g', prec, '\0');
for (char *p = buf; *p; p++) {
if (*p == '.') goto exit;
if (*p == 'e') {
memmove(p+2, p, strlen(p)+1);
memcpy(p, ".0", 2);
goto exit;
}
}
strcat(buf, ".0");
exit:
return mrb_str_new_cstr(mrb, buf);
}
#endif #endif
...@@ -277,6 +277,30 @@ flo_div(mrb_state *mrb, mrb_value x) ...@@ -277,6 +277,30 @@ flo_div(mrb_state *mrb, mrb_value x)
return mrb_float_value(mrb, a); return mrb_float_value(mrb, a);
} }
MRB_API mrb_value
mrb_float_to_str(mrb_state *mrb, mrb_value flo)
{
char buf[25];
#ifdef MRB_USE_FLOAT32
const int prec = 7;
#else
const int prec = 15;
#endif
mrb_format_float(mrb_float(flo), buf, sizeof(buf), 'g', prec, '\0');
for (char *p = buf; *p; p++) {
if (*p == '.') goto exit;
if (*p == 'e') {
memmove(p+2, p, strlen(p)+1);
memcpy(p, ".0", 2);
goto exit;
}
}
strcat(buf, ".0");
exit:
return mrb_str_new_cstr(mrb, buf);
}
/* 15.2.9.3.16(x) */ /* 15.2.9.3.16(x) */
/* /*
* call-seq: * call-seq:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment