Skip to content

Commit

Permalink
fix nearbyint and rint to round ties to even
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Mar 1, 2024
1 parent 6d05920 commit 19f3fa7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
57 changes: 30 additions & 27 deletions cli/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3953,7 +3953,7 @@
- name: trigonometric functions
args:
- -c
- 'map(sin),map(cos),map(tan) | map(. * 1000000000 | floor / 1000000000)'
- 'map(sin), map(cos), map(tan) | map(. * 1000000000 | floor / 1000000000)'
input: '[0, 1, 2]'
expected: |
[0,0.841470984,0.909297426]
Expand All @@ -3963,7 +3963,7 @@
- name: inverse trigonometric functions
args:
- -c
- 'map(asin),map(acos),map(atan) | map(. * 1000000000 | floor / 1000000000)'
- 'map(asin), map(acos), map(atan) | map(. * 1000000000 | floor / 1000000000)'
input: '[0, 1, 2]'
expected: |
[0,1.570796326,null]
Expand All @@ -3973,7 +3973,7 @@
- name: hyperbolic functions
args:
- -c
- 'map(sinh),map(cosh),map(tanh) | map(. * 1000000000 | floor / 1000000000)'
- 'map(sinh), map(cosh), map(tanh) | map(. * 1000000000 | floor / 1000000000)'
input: '[0, 1, 2]'
expected: |
[0,1.175201193,3.626860407]
Expand All @@ -3983,39 +3983,42 @@
- name: inverse hyperbolic functions
args:
- -c
- 'map(asinh),map(acosh),map(atanh) | map(. * 1000000000 | floor / 1000000000)'
- 'map(asinh), map(acosh), map(atanh) | map(. * 1000000000 | floor / 1000000000)'
input: '[0, 1, 2]'
expected: |
[0,0.881373587,1.443635475]
[null,0,1.316957896]
[0,1.7976931348623157e+308,null]
- name: floor, round, nearbyint, rint, ceil, trunc, fabs, sqrt and cbrt functions
- name: floor, ceil, trunc, fabs functions
args:
- -c
- 'range(.) | sin | (fabs,sqrt,cbrt,sin) * 100000 | [(floor,round,nearbyint,rint,ceil,trunc) / 100000]'
input: '5'
- 'map(floor), map(ceil), map(trunc), map(fabs)'
input: '[-3.7, -3.3, -2.5, -1.7, -1.0, -0.7, -0.3, 0.0, 0.3, 0.5, 0.7, 1.0, 1.7, 2.5, 3.3, 3.7]'
expected: |
[0,0,0,0,0,0]
[0,0,0,0,0,0]
[0,0,0,0,0,0]
[0,0,0,0,0,0]
[0.84147,0.84147,0.84147,0.84147,0.84148,0.84147]
[0.91731,0.91732,0.91732,0.91732,0.91732,0.91731]
[0.94408,0.94409,0.94409,0.94409,0.94409,0.94408]
[0.74562,0.74562,0.74562,0.74562,0.74563,0.74562]
[0.90929,0.9093,0.9093,0.9093,0.9093,0.90929]
[0.95357,0.95357,0.95357,0.95357,0.95358,0.95357]
[0.9688,0.9688,0.9688,0.9688,0.96881,0.9688]
[0.78907,0.78907,0.78907,0.78907,0.78908,0.78907]
[0.14112,0.14112,0.14112,0.14112,0.14113,0.14112]
[0.37565,0.37566,0.37566,0.37566,0.37566,0.37565]
[0.52063,0.52063,0.52063,0.52063,0.52064,0.52063]
[0.14065,0.14065,0.14065,0.14065,0.14066,0.14065]
[0.7568,0.7568,0.7568,0.7568,0.75681,0.7568]
[null,null,null,null,null,null]
[-0.9113,-0.9113,-0.9113,-0.9113,-0.91129,-0.91129]
[-0.68661,-0.6866,-0.6866,-0.6866,-0.6866,-0.6866]
[-4,-4,-3,-2,-1,-1,-1,0,0,0,0,1,1,2,3,3]
[-3,-3,-2,-1,-1,-0,-0,0,1,1,1,1,2,3,4,4]
[-3,-3,-2,-1,-1,-0,-0,0,0,0,0,1,1,2,3,3]
[3.7,3.3,2.5,1.7,1,0.7,0.3,0,0.3,0.5,0.7,1,1.7,2.5,3.3,3.7]
- name: round, nearbyint, rint functions
args:
- -c
- 'map(round), map(nearbyint), map(rint)'
input: '[-2.5, -1.7, -1.5, -1.2, -0.7, -0.5, -0.3, 0.0, 0.3, 0.5, 0.7, 1.2, 1.5, 1.7, 2.5]'
expected: |
[-3,-2,-2,-1,-1,-1,-0,0,0,1,1,1,2,2,3]
[-2,-2,-2,-1,-1,-0,-0,0,0,0,1,1,2,2,2]
[-2,-2,-2,-1,-1,-0,-0,0,0,0,1,1,2,2,2]
- name: sqrt and cbrt functions
args:
- -c
- 'map(sqrt), map(cbrt) | map(. * 1000000000 | floor / 1000000000)'
input: '[-8, -3.375, 0, 0.125, 1, 4, 8, 40.96, 64]'
expected: |
[null,null,0,0.35355339,1,2,2.828427124,6.4,8]
[-2,-1.5,0,0.5,1,1.587401051,2,3.447095504,4]
- name: significand function
args:
Expand Down
4 changes: 2 additions & 2 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func init() {
"atanh": mathFunc("atanh", math.Atanh),
"floor": mathFunc("floor", math.Floor),
"round": mathFunc("round", math.Round),
"nearbyint": mathFunc("nearbyint", math.Round),
"rint": mathFunc("rint", math.Round),
"nearbyint": mathFunc("nearbyint", math.RoundToEven),
"rint": mathFunc("rint", math.RoundToEven),
"ceil": mathFunc("ceil", math.Ceil),
"trunc": mathFunc("trunc", math.Trunc),
"significand": mathFunc("significand", funcSignificand),
Expand Down

0 comments on commit 19f3fa7

Please sign in to comment.