Skip to content

Commit 5e70ed7

Browse files
feat: implement std.round (#1064)
Co-authored-by: Dave Cunningham <[email protected]>
1 parent fa49977 commit 5e70ed7

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ local html = import 'html.libsonnet';
183183
<ul><code>std.asin(x)</code></ul>
184184
<ul><code>std.acos(x)</code></ul>
185185
<ul><code>std.atan(x)</code></ul>
186+
<ul><code>std.round(x)</code></ul>
186187
</ul>
187188
<p>
188189
The function <code>std.mod(a, b)</code> is what the % operator is desugared to. It performs

stdlib/std.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,5 +1707,7 @@ limitations under the License.
17071707

17081708
xnor(x, y):: x == y,
17091709

1710+
round(x):: std.floor(x + 0.5),
1711+
17101712
isEmpty(str):: std.length(str) == 0,
17111713
}

test_suite/stdlib.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,9 @@ std.assertEqual(std.xor(true, true), false) &&
15501550
std.assertEqual(std.xnor(true, false), false) &&
15511551
std.assertEqual(std.xnor(true, true), true) &&
15521552

1553+
std.assertEqual(std.round(1.2), 1) &&
1554+
std.assertEqual(std.round(1.5), 2) &&
1555+
15531556
std.assertEqual(std.isEmpty(''), true) &&
15541557
std.assertEqual(std.isEmpty('non-empty string'), false) &&
15551558

0 commit comments

Comments
 (0)