change the behavior of pf_number_div upon divide by zero

This commit is contained in:
hyunghwan.chung 2019-01-10 15:22:43 +00:00
parent 7d3d21b3cf
commit 9cd0b28933
2 changed files with 13 additions and 2 deletions

View File

@ -209,7 +209,18 @@ extend MyObject
[ (16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF bitAnd: 16r1111111111111111111111111111111111111111) = 16r1111111111111111111111111111111111111111 ], [ (16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF bitAnd: 16r1111111111111111111111111111111111111111) = 16r1111111111111111111111111111111111111111 ],
## 60-64 ## 60-64
[ (-0.1233 * 999999.123) = -123299.8918 ],
[ (-0.1233 * 999999.123) asString = '-123299.8918' ],
[ (-0.1233 - -0.123) = -0.0003 ],
[ (-0.1233 - -0.123) asString = '-0.0003' ],
[ (1.234 - 1.234) = 0 ], ## 0.000
## 65-69
[ (-123897128378912738912738917.112323131233 div: 123.1) = -1006475453931053931053931.089458352000 ],
[ (-1006475453931053931053931.089458352000 * 123.1) = -123897128378912738912738917.112323131200 ],
[ [
| b | | b |
b := [:n | (n > 0) ifTrue: [ n * (b value: n - 1)] ifFalse: [1]]. b := [:n | (n > 0) ifTrue: [ n * (b value: n - 1)] ifFalse: [1]].

View File

@ -2880,7 +2880,7 @@ static moo_pfrc_t pf_number_div (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
arg = MOO_STACK_GETARG(moo, nargs, 0); arg = MOO_STACK_GETARG(moo, nargs, 0);
res = moo_divnums(moo, rcv, arg, 0); res = moo_divnums(moo, rcv, arg, 0);
if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); if (!res) return (moo->errnum == MOO_EINVAL || moo->errnum == MOO_EDIVBY0? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE);
MOO_STACK_SETRET (moo, nargs, res); MOO_STACK_SETRET (moo, nargs, res);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
@ -2896,7 +2896,7 @@ static moo_pfrc_t pf_number_mdiv (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
arg = MOO_STACK_GETARG(moo, nargs, 0); arg = MOO_STACK_GETARG(moo, nargs, 0);
res = moo_divnums(moo, rcv, arg, 1); res = moo_divnums(moo, rcv, arg, 1);
if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); if (!res) return (moo->errnum == MOO_EINVAL || moo->errnum == MOO_EDIVBY0? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE);
MOO_STACK_SETRET (moo, nargs, res); MOO_STACK_SETRET (moo, nargs, res);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;