Skip to content

Integer division / std.trunc ? #919

Open
@candlerb

Description

@candlerb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions