google / google/jsonnet

Integer division / std.trunc ?

Open
#919 1 comment 0 reactions 0 assignees View on GitHub
stdlib
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

It's easy to get the remainder when dividing two integers:

```
$ jsonnet -e -- '105 % 100'
5
$ jsonnet -e -- '-105 % 100'
-5
```

But I found it unexpectedly awkward to do the actual division:

```
$ jsonnet -e -- 'std.floor(105 / 100)'
1
$ jsonnet -e -- 'std.floor(-105 / 100)'
-2
```

In javascript there would be `Math.trunc` for this. Of course, you can write it yourself if you need it.

I wonder if `std.trunc` would be a useful addition? Or `std.div` for integer division?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.