diff options
| author | Masaki Muranaka <[email protected]> | 2013-03-29 21:48:18 +0900 |
|---|---|---|
| committer | Masaki Muranaka <[email protected]> | 2013-03-29 22:19:26 +0900 |
| commit | 710f6252548f4a0eaf16a7b0d4d973a50e4520c0 (patch) | |
| tree | 65451ed5edb13ae70e56da71332f2a714059224d /src/numeric.c | |
| parent | 6818ec0b38fdf2bd027b2088ed99606d74358d99 (diff) | |
| download | mruby-710f6252548f4a0eaf16a7b0d4d973a50e4520c0.tar.gz mruby-710f6252548f4a0eaf16a7b0d4d973a50e4520c0.zip | |
Remove mrb_flt2big() as there is no bignum in the core.
Add new API mrb_flo_to_fixnum(). You can replace mrb_flt2big() to mrb_flo_to_fixnum() with few modifications.
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/numeric.c b/src/numeric.c index 084243291..02a18c130 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1175,25 +1175,27 @@ fix_to_f(mrb_state *mrb, mrb_value num) * FloatDomainError: Infinity */ /* ------------------------------------------------------------------------*/ -static mrb_int -flt2big(mrb_state *mrb, mrb_float d) +mrb_value +mrb_flo_to_fixnum(mrb_state *mrb, mrb_value x) { mrb_int z; - if (isinf(d)) { - mrb_raise(mrb, E_FLOATDOMAIN_ERROR, d < 0 ? "-Infinity" : "Infinity"); - } - if (isnan(d)) { - mrb_raise(mrb, E_FLOATDOMAIN_ERROR, "NaN"); + if (mrb_float_p(x)) { + mrb_raise(mrb, E_TYPE_ERROR, "non float value"); + z = 0; /* not reached. just supress warnings. */ } - z = (mrb_int)d; - return z; -} + else { + mrb_float d = mrb_float(x); -mrb_value -mrb_flt2big(mrb_state *mrb, mrb_float d) -{ - return mrb_fixnum_value(flt2big(mrb, d)); + if (isinf(d)) { + mrb_raise(mrb, E_FLOATDOMAIN_ERROR, d < 0 ? "-Infinity" : "Infinity"); + } + if (isnan(d)) { + mrb_raise(mrb, E_FLOATDOMAIN_ERROR, "NaN"); + } + z = (mrb_int)d; + } + return mrb_fixnum_value(z); } mrb_value |
