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.
This commit is contained in:
卜部昌平 2020-06-16 15:18:55 +09:00
parent d7eec15f8e
commit 689dd3aecb
Notes: git 2020-06-29 11:06:52 +09:00

View File

@ -2440,24 +2440,27 @@ parse_rat(const char *s, const char *const e, int strict, int raise)
if (nexp != ZERO) { if (nexp != ZERO) {
if (INT_NEGATIVE_P(nexp)) { if (INT_NEGATIVE_P(nexp)) {
VALUE mul; VALUE mul;
if (!FIXNUM_P(nexp)) { if (FIXNUM_P(nexp)) {
overflow:
return sign == '-' ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
}
mul = f_expt10(LONG2NUM(-FIX2LONG(nexp))); mul = f_expt10(LONG2NUM(-FIX2LONG(nexp)));
if (RB_FLOAT_TYPE_P(mul)) goto overflow; if (! RB_FLOAT_TYPE_P(mul)) {
num = rb_int_mul(num, mul); num = rb_int_mul(num, mul);
goto reduce;
}
}
return sign == '-' ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
} }
else { else {
VALUE div; VALUE div;
if (!FIXNUM_P(nexp)) { if (FIXNUM_P(nexp)) {
underflow: div = f_expt10(nexp);
if (! RB_FLOAT_TYPE_P(div)) {
den = rb_int_mul(den, div);
goto reduce;
}
}
return sign == '-' ? DBL2NUM(-0.0) : DBL2NUM(+0.0); return sign == '-' ? DBL2NUM(-0.0) : DBL2NUM(+0.0);
} }
div = f_expt10(nexp); reduce:
if (RB_FLOAT_TYPE_P(div)) goto underflow;
den = rb_int_mul(den, div);
}
nurat_reduce(&num, &den); nurat_reduce(&num, &den);
} }