diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-02 23:36:41 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-02 23:36:41 +0900 |
| commit | 757902c497c01c88b4e960ca81ba491bf8728b45 (patch) | |
| tree | 3f180d648aa30e8047c81ff4ac08a3396542c77f | |
| parent | 392aff70992260267590f431fb50c87b9d445ce2 (diff) | |
| download | mruby-757902c497c01c88b4e960ca81ba491bf8728b45.tar.gz mruby-757902c497c01c88b4e960ca81ba491bf8728b45.zip | |
Check `NaN` and `Infinity` before converting `Float` to `Rational`.
| -rw-r--r-- | mrbgems/mruby-rational/src/rational.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 1feb2530e..a151e0453 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -105,6 +105,9 @@ typedef float rat_float; #else typedef double rat_float; #endif + +void mrb_check_num_exact(mrb_state *mrb, mrb_float num); + static mrb_value rational_new_f(mrb_state *mrb, mrb_float f0) { @@ -116,6 +119,7 @@ rational_new_f(mrb_state *mrb, mrb_float f0) int64_t n = 1; int i, neg = 0; + mrb_check_num_exact(mrb, f0); if (f < 0) { neg = 1; f = -f; } while (f != floor(f)) { n <<= 1; f *= 2; } if (!TYPED_FIXABLE(f, rat_float)) { |
