@@ -438,7 +438,7 @@ func (x *bound) binOp(ctx *context, src source, op op, other evaluated) evaluate
438
438
439
439
case diff == 2 :
440
440
if k & floatKind == 0 && x .op == opGtr && y .op == opLss {
441
- apd .BaseContext .Add (& d , d .SetInt64 (1 ), & a .v )
441
+ _ , _ = apd .BaseContext .Add (& d , d .SetInt64 (1 ), & a .v )
442
442
n := * a
443
443
n .k = k
444
444
n .v = d
@@ -902,22 +902,37 @@ func (x *numLit) binOp(ctx *context, src source, op op, other evaluated) evaluat
902
902
case opLss , opLeq , opEql , opNeq , opGeq , opGtr :
903
903
return cmpTonode (src , op , x .v .Cmp (& y .v ))
904
904
case opAdd :
905
- ctx .Add (& n .v , & x .v , & y .v )
905
+ _ , _ = ctx .Add (& n .v , & x .v , & y .v )
906
906
case opSub :
907
- ctx .Sub (& n .v , & x .v , & y .v )
907
+ _ , _ = ctx .Sub (& n .v , & x .v , & y .v )
908
908
case opMul :
909
- ctx .Mul (& n .v , & x .v , & y .v )
909
+ _ , _ = ctx .Mul (& n .v , & x .v , & y .v )
910
910
case opQuo :
911
- ctx .Quo (& n .v , & x .v , & y .v )
912
- ctx .Reduce (& n .v , & n .v )
911
+ cond , _ := ctx .Quo (& n .v , & x .v , & y .v )
912
+ if cond .DivisionByZero () {
913
+ return ctx .mkErr (src , "divide by zero" )
914
+ }
915
+ _ , _ , _ = ctx .Reduce (& n .v , & n .v )
913
916
n .k = floatKind
914
917
case opIDiv :
918
+ if y .v .IsZero () {
919
+ return ctx .mkErr (src , "divide by zero" )
920
+ }
915
921
intOp (ctx , n , (* big .Int ).Div , x , y )
916
922
case opIMod :
923
+ if y .v .IsZero () {
924
+ return ctx .mkErr (src , "divide by zero" )
925
+ }
917
926
intOp (ctx , n , (* big .Int ).Mod , x , y )
918
927
case opIQuo :
928
+ if y .v .IsZero () {
929
+ return ctx .mkErr (src , "divide by zero" )
930
+ }
919
931
intOp (ctx , n , (* big .Int ).Quo , x , y )
920
932
case opIRem :
933
+ if y .v .IsZero () {
934
+ return ctx .mkErr (src , "divide by zero" )
935
+ }
921
936
intOp (ctx , n , (* big .Int ).Rem , x , y )
922
937
}
923
938
return n
@@ -938,11 +953,11 @@ type intFunc func(z, x, y *big.Int) *big.Int
938
953
939
954
func intOp (ctx * context , n * numLit , fn intFunc , a , b * numLit ) {
940
955
var x , y apd.Decimal
941
- ctx .RoundToIntegralValue (& x , & a .v )
956
+ _ , _ = ctx .RoundToIntegralValue (& x , & a .v )
942
957
if x .Negative {
943
958
x .Coeff .Neg (& x .Coeff )
944
959
}
945
- ctx .RoundToIntegralValue (& y , & b .v )
960
+ _ , _ = ctx .RoundToIntegralValue (& y , & b .v )
946
961
if y .Negative {
947
962
y .Coeff .Neg (& y .Coeff )
948
963
}
@@ -990,7 +1005,8 @@ func (x *durationLit) binOp(ctx *context, src source, op op, other evaluated) ev
990
1005
}
991
1006
n .v .SetInt64 (int64 (x .d ))
992
1007
d := apd .New (int64 (y .d ), 0 )
993
- ctx .Quo (& n .v , & n .v , d )
1008
+ // TODO: check result if this code becomes undead.
1009
+ _ , _ = ctx .Quo (& n .v , & n .v , d )
994
1010
return n
995
1011
case opIRem :
996
1012
n := & numLit {
0 commit comments