yq/pkg/yqlib/doc/operators/divide.md
William Floyd 30e16a33c3
Fix for #2677 (#2705)
* Update docs given https://github.com/yaml/go-yaml/pull/348

* Fix for https://github.com/mikefarah/yq/issues/2677

Depends on https://github.com/yaml/go-yaml/pull/348

* Test for https://github.com/mikefarah/yq/issues/2677

* Remove redundant check and add test case for explicit `!!merge` on `*+` traversal

* Bump go.yaml.in/yaml/v4 from 4.0.0-rc.4 to 4.0.0-rc.5
2026-06-09 14:08:47 +10:00

745 B

Divide

Divide behaves differently according to the type of the LHS:

  • strings: split by the divider
  • number: arithmetic division

String split

Given a sample.yml file of:

a: cat_meow
b: _

then

yq '.c = .a / .b' sample.yml

will output

a: cat_meow
b: _
c:
  - cat
  - meow

Number division

The result during division is calculated as a float

Given a sample.yml file of:

a: 12
b: 2.5

then

yq '.a = .a / .b' sample.yml

will output

a: 4.8
b: 2.5

Number division by zero

Dividing by zero results in +Inf or -Inf

Given a sample.yml file of:

a: 1
b: -1

then

yq '.a = .a / 0 | .b = .b / 0' sample.yml

will output

a: +Inf
b: -Inf