This PR basically changes the * to + and adds a test case.
Natural.toNat n =
match digits n with
Nonempty a [b] ->
use Nat +
- Some (a * Nat.shiftLeft b 32)
+ Some (a + Nat.shiftLeft b 32)
_ -> None
Ideally this bug should have been discovered by the existing property test Natural.toNat.tests.roundtrip. But with the generator gen.nat it only tests the cases from 0 to 999 unfortunately.
Btw. this is my first PR to a unison codebase. I tried to follow the instructions in CONTRIBUTING.md and hope everything is fine, but please check carefully if I missed anything
Code review
The changes summarized below are available for you to review, using the following command:
The original code of
Natural.toNat
multiplies the upper and lower 32bits instead of adding them, so for any Natural > 0xFFFFFFFF the result is wrong.Fixes https://github.com/unisonweb/base/issues/57
This PR basically changes the * to + and adds a test case.
Ideally this bug should have been discovered by the existing property test
Natural.toNat.tests.roundtrip
. But with the generatorgen.nat
it only tests the cases from 0 to 999 unfortunately.Btw. this is my first PR to a unison codebase. I tried to follow the instructions in CONTRIBUTING.md and hope everything is fine, but please check carefully if I missed anything
Code review
The changes summarized below are available for you to review, using the following command:
Updates:
Added definitions: