feature request: power operator
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Description
We should have a binary operator `x ** y` which desugars to `std.pow(x, y)`. Its operator precedence should be between the unary operators and `*` - that is, `20 * 2**30` should be equivalent to `20 * (2**30)` and equal `21474836480`.
This is a very common operation when dealing with certain kinds of numbers, such as byte amounts (eg. in the example above, we are calculating the number of bytes in 20 GiB), and `std.pow(2, 30)` isn't as readable as `2 ** 30`, especially in more complex expressions (you could argue that I could use `1 << 30` in this particular example, but that only works for powers of 2 and is even less readable).
The use of `**` as the operator (since the traditional choice of `^` is already in use for bitwise XOR) mimics python, javascript and ruby and should be familiar to most users. I was surprised to find it wasn't already implemented.
Contributor guide
Assessment
This issue has not been assessed yet.