From 9cd0b28933ebd69a94bd7d6034e97940f1a4d421 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 10 Jan 2019 15:22:43 +0000 Subject: [PATCH] change the behavior of pf_number_div upon divide by zero --- moo/kernel/test-001.moo | 11 +++++++++++ moo/lib/exec.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/moo/kernel/test-001.moo b/moo/kernel/test-001.moo index add4a78..c55aead 100644 --- a/moo/kernel/test-001.moo +++ b/moo/kernel/test-001.moo @@ -209,7 +209,18 @@ extend MyObject [ (16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF bitAnd: 16r1111111111111111111111111111111111111111) = 16r1111111111111111111111111111111111111111 ], + ## 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 := [:n | (n > 0) ifTrue: [ n * (b value: n - 1)] ifFalse: [1]]. diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 09fd748..5db44e0 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -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); 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); 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); 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); return MOO_PF_SUCCESS;