Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions book/src/command/super.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions runtime/sam/expr/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions runtime/ztests/expr/arith-divide-by-zero.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")