From 15f46a1feba74cba4f25ec99df79a3f1e07b0b09 Mon Sep 17 00:00:00 2001 From: Yuichiro MASUI Date: Sat, 27 Oct 2012 14:26:50 +0900 Subject: define convert method mrb_int/mrb_float with C string --- include/mrbconf.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index 76c1b37f9..841ef1823 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -55,19 +55,26 @@ #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) (mrb_float)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) (mrb_float)strtod((buf),NULL) #endif -#define readfloat(p) (mrb_float)strtod((p),NULL) #ifdef MRB_NAN_BOXING typedef int32_t mrb_int; #define MRB_INT_MIN INT32_MIN #define MRB_INT_MAX INT32_MAX +#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i)) +#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10); #else typedef int mrb_int; #define MRB_INT_MIN INT_MIN #define MRB_INT_MAX INT_MAX +#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i)) +#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10); #endif typedef short mrb_sym; -- cgit v1.2.3