Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shyouhei committed Jun 29, 2020
1 parent d7eec15 commit 689dd3a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions rational.c
Expand Up @@ -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);
if (FIXNUM_P(nexp)) {
mul = f_expt10(LONG2NUM(-FIX2LONG(nexp)));
if (! RB_FLOAT_TYPE_P(mul)) {
num = rb_int_mul(num, mul);
goto reduce;
}
}
mul = f_expt10(LONG2NUM(-FIX2LONG(nexp)));
if (RB_FLOAT_TYPE_P(mul)) goto overflow;
num = rb_int_mul(num, mul);
return sign == '-' ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
}
else {
VALUE div;
if (!FIXNUM_P(nexp)) {
underflow:
return sign == '-' ? DBL2NUM(-0.0) : DBL2NUM(+0.0);
if (FIXNUM_P(nexp)) {
div = f_expt10(nexp);
if (! RB_FLOAT_TYPE_P(div)) {
den = rb_int_mul(den, div);
goto reduce;
}
}
div = f_expt10(nexp);
if (RB_FLOAT_TYPE_P(div)) goto underflow;
den = rb_int_mul(den, div);
return sign == '-' ? DBL2NUM(-0.0) : DBL2NUM(+0.0);
}
reduce:
nurat_reduce(&num, &den);
}

Expand Down

0 comments on commit 689dd3a

Please sign in to comment.