diff --git a/pkg/yqlib/doc/operators/divide.md b/pkg/yqlib/doc/operators/divide.md index bf005e4a..22a917a4 100644 --- a/pkg/yqlib/doc/operators/divide.md +++ b/pkg/yqlib/doc/operators/divide.md @@ -36,3 +36,21 @@ a: 4.8 b: 2.5 ``` +## Number division by zero +Dividing by zero results in +Inf or -Inf + +Given a sample.yml file of: +```yaml +a: 1 +b: -1 +``` +then +```bash +yq '.a = .a / 0 | .b = .b / 0' sample.yml +``` +will output +```yaml +a: !!float +Inf +b: !!float -Inf +``` + diff --git a/pkg/yqlib/operator_divide_test.go b/pkg/yqlib/operator_divide_test.go index d3521a6f..bbdc1339 100644 --- a/pkg/yqlib/operator_divide_test.go +++ b/pkg/yqlib/operator_divide_test.go @@ -39,6 +39,15 @@ var divideOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{a: 4.8, b: 2.5}\n", }, }, + { + description: "Number division by zero", + subdescription: "Dividing by zero results in +Inf or -Inf", + document: `{a: 1, b: -1}`, + expression: `.a = .a / 0 | .b = .b / 0`, + expected: []string{ + "D0, P[], (doc)::{a: !!float +Inf, b: !!float -Inf}\n", + }, + }, { skipDoc: true, description: "Custom types: that are really strings",