diff --git a/book/src/command/super.md b/book/src/command/super.md index 3f624a262..5cb335f26 100644 --- a/book/src/command/super.md +++ b/book/src/command/super.md @@ -500,18 +500,18 @@ or trying to debug a halted query with a vague error message. For example, this query ```mdtest-command -echo '1 2 0 3' | super -s -c '10.0/this' - +echo '1 2 0 5' | super -s -c '10/this' - ``` produces ```mdtest-output -10. -5. +10 +5 error("divide by zero") -3.3333333333333335 +2 ``` and ```mdtest-command -echo '1 2 0 3' | super -c '10.0/this' - | super -s -c 'is_error(this)' - +echo '1 2 0 5' | super -c '10/this' - | super -s -c 'is_error(this)' - ``` produces just ```mdtest-output diff --git a/runtime/sam/expr/eval.go b/runtime/sam/expr/eval.go index c3893e913..483c65484 100644 --- a/runtime/sam/expr/eval.go +++ b/runtime/sam/expr/eval.go @@ -522,11 +522,7 @@ func (d *Divide) Eval(this super.Value) super.Value { } return super.NewInt(typ, toInt(lhsVal)/v) case super.IsFloat(id): - v := toFloat(rhsVal) - if v == 0 { - return d.sctx.NewError(DivideByZero) - } - return super.NewFloat(typ, toFloat(lhsVal)/v) + return super.NewFloat(typ, toFloat(lhsVal)/toFloat(rhsVal)) } return d.sctx.NewErrorf("type %s incompatible with '/' operator", sup.FormatType(typ)) } diff --git a/runtime/ztests/expr/arith-divide-by-zero.yaml b/runtime/ztests/expr/arith-divide-by-zero.yaml index c18f4d655..27f8c214d 100644 --- a/runtime/ztests/expr/arith-divide-by-zero.yaml +++ b/runtime/ztests/expr/arith-divide-by-zero.yaml @@ -6,6 +6,8 @@ input: | {a:null::uint64,b:0::uint64} {a:2::uint64,b:null::uint64} {a:5::uint64,b:0::uint64} + {a:1.,b:0.} + {a:-1.,b:0.} output: | null::uint64 @@ -14,3 +16,7 @@ output: | null::uint64 error("divide by zero") error("divide by zero") + +Inf + error("type float64 incompatible with '%' operator") + -Inf + error("type float64 incompatible with '%' operator")