Skip to content
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

Expose new bit operations on NatN and IntN #217

Merged
merged 3 commits into from
Feb 12, 2021
Merged

Conversation

nomeata
Copy link
Contributor

@nomeata nomeata commented Feb 10, 2021

this goes along with dfinity/motoko#2326
(and should not be merged before). It adds new bit operations, wrapping
arithmetic and conversions to IntN and NatN.

It does not port the rest of base to avoid Word. See #214 for that (and
we will likely pull that in selectively).

this goes along with dfinity/motoko#2326
(and should not be merged before). It adds new bit operations, wrapping
arithmetic and conversions to IntN and NatN.

It does not port the rest of base to avoid Word. See #214 for that (and
we will likely pull that in selectively).
nomeata added a commit to dfinity/motoko that referenced this pull request Feb 10, 2021
this tests  dfinity/motoko-base#217 against
#2326.

Before this can be merged, #2326 needs to be merged, then
dfinity/motoko-base#217 into `next-moc`, then
this updated to to point to `next-moc`.

But it can be approved already ;-)
so that users can migrate away from `Char.fromWord32` already
this avoids deprecation warnings in the upcoming compiler version.
mergify bot pushed a commit to dfinity/motoko that referenced this pull request Feb 12, 2021
* 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)
@nomeata nomeata marked this pull request as ready for review February 12, 2021 13:55
@nomeata nomeata merged commit 46d02d0 into next-moc Feb 12, 2021
@nomeata nomeata deleted the joachim/new-bit-ops branch February 12, 2021 13:55
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.

2 participants