Change the second argument of mrb_flo_to_str().

Export mrb_flo_to_str() as API.
This commit is contained in:
Masaki Muranaka
2013-03-29 21:56:41 +09:00
parent 710f625254
commit f82ae7653a
2 changed files with 11 additions and 3 deletions
+2
View File
@@ -16,6 +16,8 @@ extern "C" {
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
mrb_value mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit);
mrb_value mrb_fix2str(mrb_state *mrb, mrb_value x, int base);
mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y);
+9 -3
View File
@@ -163,13 +163,19 @@ num_abs(mrb_state *mrb, mrb_value num)
*/
mrb_value
mrb_flo_to_str(mrb_state *mrb, mrb_float n, int max_digit)
mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit)
{
mrb_value result;
mrb_float n;
if (max_digit > 40) {
mrb_raise(mrb, E_RANGE_ERROR, "Too large max_digit.");
}
else if (!mrb_float_p(flo)) {
mrb_raise(mrb, E_TYPE_ERROR, "non float value");
}
n = mrb_float(flo);
if (isnan(n)) {
result = mrb_str_new(mrb, "NaN", 3);
@@ -270,9 +276,9 @@ static mrb_value
flo_to_s(mrb_state *mrb, mrb_value flt)
{
#ifdef MRB_USE_FLOAT
return mrb_flo_to_str(mrb, mrb_float(flt), 7);
return mrb_flo_to_str(mrb, flt, 7);
#else
return mrb_flo_to_str(mrb, mrb_float(flt), 14);
return mrb_flo_to_str(mrb, flt, 14);
#endif
}