summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorcremno <[email protected]>2015-02-13 09:33:03 +0100
committercremno <[email protected]>2015-02-13 09:33:03 +0100
commit6f893b5183450384e89b3d8f03f9ef32a7522624 (patch)
tree481913e69c91974e18c4e2355ef7778f9f0ae93d /include
parent789177c8fe6c3bcb3833e76f95ecbd41b43b83fd (diff)
downloadmruby-6f893b5183450384e89b3d8f03f9ef32a7522624.tar.gz
mruby-6f893b5183450384e89b3d8f03f9ef32a7522624.zip
re-implement mrb_float_to_str()
The new implementation is backwards incompatible, but I couldn't find any usage outside mruby and I also couldn't think of a different and good name. All ISO C99 printf conversion specifiers for floating point numbers and an optional precision are supported. It is largely based on code from the MIT licensed musl libc (http://www.musl-libc.org/) and its floating point printing is exact (unlike the current code behind Float#to_s).
Diffstat (limited to 'include')
-rw-r--r--include/mruby/numeric.h2
-rw-r--r--include/mruby/value.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h
index 3020dbd93..94cdbccee 100644
--- a/include/mruby/numeric.h
+++ b/include/mruby/numeric.h
@@ -17,6 +17,8 @@ extern "C" {
MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base);
+/* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */
+MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y);
diff --git a/include/mruby/value.h b/include/mruby/value.h
index 9297f6b28..f27800366 100644
--- a/include/mruby/value.h
+++ b/include/mruby/value.h
@@ -34,11 +34,9 @@ struct mrb_state;
#ifdef MRB_USE_FLOAT
typedef float mrb_float;
-# define mrb_float_to_str(buf, i) sprintf(buf, "%.7e", i)
# define str_to_mrb_float(buf) strtof(buf, NULL)
#else
typedef double mrb_float;
-# define mrb_float_to_str(buf, i) sprintf(buf, "%.16e", i)
# define str_to_mrb_float(buf) strtod(buf, NULL)
#endif