Skip to content

Comments

Guard against Motoko 32 bit values overflowing the compiler's 31-bit arithmetic#2686

Merged
mergify[bot] merged 2 commits intomasterfrom
gabor/js-int
Jul 28, 2021
Merged

Guard against Motoko 32 bit values overflowing the compiler's 31-bit arithmetic#2686
mergify[bot] merged 2 commits intomasterfrom
gabor/js-int

Conversation

@ggreif
Copy link
Contributor

@ggreif ggreif commented Jul 28, 2021

Since NumType.of_int returns an int, this has not enough precision (just 31 bits) when
the compiler is 32-bit, e.g. on JS (Motoko Playground)

This patch switches to using Big_int instead.

Fixes #2671.

…arithmetic

since `of_int` returns an `int`, this has not enough precision (31 bits) when
the compiler is 32-bit, e.g. on JS (Motoko Playground)

In long term we should get rid of `of_int`.
@dfinity-ci
Copy link

This PR does not affect the produced WebAssembly code.

@crusso
Copy link
Contributor

crusso commented Jul 28, 2021

Nice catch!

Copy link
Contributor

@chenyan-dfinity chenyan-dfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in the playground!

@ggreif ggreif added the automerge-squash When ready, merge (using squash) label Jul 28, 2021
@mergify mergify bot merged commit 047e701 into master Jul 28, 2021
@mergify mergify bot deleted the gabor/js-int branch July 28, 2021 18:56
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Large Nat32 literal overflow in JS

4 participants