diff options
author | 卜部昌平 <[email protected]> | 2020-06-16 15:18:55 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2020-06-29 11:05:41 +0900 |
commit | 689dd3aecbf6177caad793c18c1c6ab4a7cc2150 () | |
tree | 5e7249ec7f394b93c6f16042bfa6d3a4ae20a3bd /rational.c | |
parent | d7eec15f8e7e8667cdca144a1e288a3f72015d30 (diff) |
parse_rat: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
Notes: Merged: https://.com/ruby/ruby/pull/3247
-rw-r--r-- | rational.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -2440,24 +2440,27 @@ parse_rat(const char *s, const char *const e, int strict, int raise) if (nexp != ZERO) { if (INT_NEGATIVE_P(nexp)) { VALUE mul; - if (!FIXNUM_P(nexp)) { - overflow: - return sign == '-' ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL); } - mul = f_expt10(LONG2NUM(-FIX2LONG(nexp))); - if (RB_FLOAT_TYPE_P(mul)) goto overflow; - num = rb_int_mul(num, mul); } else { VALUE div; - if (!FIXNUM_P(nexp)) { - underflow: - return sign == '-' ? DBL2NUM(-0.0) : DBL2NUM(+0.0); } - div = f_expt10(nexp); - if (RB_FLOAT_TYPE_P(div)) goto underflow; - den = rb_int_mul(den, div); } nurat_reduce(&num, &den); } |