summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-05-25 13:30:17 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-05-25 13:30:17 +0900
commit5ed3a3475e5cf115cb65c8c0b1b8e37aa303996b (patch)
tree2b3c7cdef8c9e8da2f71176d549154fb6e44aa4c /src
parentbf523b71d1e9722f7a468fae8321b5a24f06ab97 (diff)
downloadmruby-5ed3a3475e5cf115cb65c8c0b1b8e37aa303996b.tar.gz
mruby-5ed3a3475e5cf115cb65c8c0b1b8e37aa303996b.zip
fmt_fp.c: use a const int instead of a macro constant.
Diffstat (limited to 'src')
-rw-r--r--src/fmt_fp.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/fmt_fp.c b/src/fmt_fp.c
index cbf1db18f..2bd5dd1c4 100644
--- a/src/fmt_fp.c
+++ b/src/fmt_fp.c
@@ -3,12 +3,6 @@
#include <stdlib.h>
#ifndef MRB_NO_FLOAT
-#ifdef MRB_USE_FLOAT32
-#define FLO_TO_STR_PREC 7
-#else
-#define FLO_TO_STR_PREC 15
-#endif
-
/***********************************************************************
Routine for converting a single-precision
@@ -368,13 +362,17 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch
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', FLO_TO_STR_PREC, '\0');
+ 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') {