-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arithmetic seems to be under-specified #120
Comments
Indeed.
The Java implementation, like the Go one, now has multiprecision integers and exact arithmetic. The Rust implementation appears to use int64 (https://github.com/google/starlark-rust/blob/8be4061e89ff088b5b219e59fa3ef360c291167c/starlark/src/values/int.rs#L88), but I am not fluent in Rust. I would like the spec to require that implementations can represent all the values of uint64 and int64 without loss, as this is a prerequisite for analysis of protocol messages. However, the difficulty and efficiency of implementing "int65" is about the same as bigint, so the spec should really just require infinite precision. It is certainly cleaner and more useful. Perhaps the Starlark-rust folks (@damienmg, @stepancheg) could chime in: how hard would it be for the Rust impl to support big ints?
Agreed. This is implied, but should be stated.
Like Python, Starlark shifts are arithmetic. This should be stated in the spec, along with the means of achieving a logical right shift.
With infinite precision, there is no "size of an int". However, one still needs a limit to avoid consuming all available memory. I think it's fine to leave that limit as an implementation detail. With finite precision, the operation may succeed but discard some high bits. It would be impractical to make it an error if the result is lossy, as this is a widely used operation, but this makes the finite vs infinite precision implementations very different. The ideal outcome is that precision is required to be infinite.
Seems like a reasonable addition, though there is little demand so far for a math package. |
Should be fairly trivial using something like https://github.com/rust-num/num-bigint and Rust has good support for checked operations with overflow detection, so it would be fairly simple to promote to bigints only where necessary. |
Ping @stepancheg? |
For example Jython (which looks dead, but nevertheless) is quite different from CPython https://www.jython.org/jython-old-sites/archive/21/docs/differences.html but still it was useful for lots of project. |
Thanks, Stepan. I agree that partial or nonconforming implementation are still useful, but I want to make sure we all agree that multiprecision integer arithmetic is the right goal. If so, the maintainers of the Rust implementation can treat its current behavior as a bug with whatever priority you decide. |
CC @ndmitchell |
I plan to add bigint support, since it makes the language more predictable. It's not particularly high on the todo list though, since its also not very impactful. But it is definitely on the todo list, and I agree its the right goal. |
Ok, thanks. (As a practical matter, make sure your API is ready for bigints even if the implementation isn't; it'll save you time later.) |
Fixes bazelbuild#120 Change-Id: Ia8aa6191dbbca08a80ac2bb562419a47466e01c9
Fixes bazelbuild#120 Change-Id: Ie8cd15b4d0ecaea6af3b563d9e412112c7526b39
ints and arithmetic on them seem to be a little bit loosy-goosy in the spec
3 + 3 = <dynamic error>
would be compliant. A reasonable minimum might be 32 or 64 bits.x << n
is a shorthand forx * 2**n
,x >> n
is short forx // 2**n
).**
operator.The text was updated successfully, but these errors were encountered: