-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bit-operations to NatN and IntN, and wrapping operations (#2326)
* The bit-operations are added to Nat8, Int8 etc. On these, we only have `>>` (the signeness of the shift is derived from the type), no `+>>`. That operator is only available on `WordN`, and will be removed with it. * Wrapping operators `+%`, `-%`, `*%` and `**%` are added. `*%` traps on negative exponent for `IntN`. The assignment variants (`+%=`, `-%=`, `+%=`, `**%=`) are added as well * We now have two conversions `Nat→Nat8`, a trapping and a wrapping one, and likewise for `Int→Int8`. This builds on the bifurcaton of prims in #2324 * Conversions between equal bit-width numbers are always wrapping, and exists for all of them, including directly from `NatN` to `IntN` and back. * Little testing in this PR, but #2327 (which is based on this one) does some thorough randomized checking. The test suite is ported to not use `WordN` in #2309 and also passes. * A PR against motoko-base to expose the new functionality is in dfinity/motoko-base#217. (But this PR can go in before, it is compatible with the previous base.) * A changelog entry is added * The user’s guide is updated (picking changes from #2309 as appropriate, but not removing mention of `Word` entirely)
- Loading branch information
Showing
21 changed files
with
424 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.