Skip to content

Conversation

@skilesare
Copy link

I'm not sure how to go about testing, but I tried to add tests as well. This same pattern can be followed for the hard edged NatXz. The Nat to bytes will need a bit more finesse than I have at the moment.

@nomeata
Copy link
Contributor

nomeata commented Jun 17, 2021

Thanks!

We probably want to indicate the endianness in these functions, i.e. Nat32.toBytesLE and Nat32.toBytesBE or something like that.

Also, the fromBytes function should probably do some bound checking, and return an ?Nat32 to indicate failure?

Comment on lines +149 to +152
[ Prim.natToNat8(Prim.nat32ToNat((x >> 24) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x >> 16) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x >> 8) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x & 255))) ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
[ Prim.natToNat8(Prim.nat32ToNat((x >> 24) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x >> 16) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x >> 8) & (255))),
Prim.natToNat8(Prim.nat32ToNat((x & 255))) ];
[ Prim.natToNat8(Prim.nat32ToNat(x >> 24 & 255)),
Prim.natToNat8(Prim.nat32ToNat(x >> 16 & 255)),
Prim.natToNat8(Prim.nat32ToNat(x >> 8 & 255)),
Prim.natToNat8(Prim.nat32ToNat(x & 255)) ];

Comment on lines +157 to +160
(Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24) +
(Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16) +
(Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8) +
(Prim.natToNat32(Prim.nat8ToNat(x[3])));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24) +
(Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16) +
(Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8) +
(Prim.natToNat32(Prim.nat8ToNat(x[3])));
Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24 +
Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16 +
Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8 +
Prim.natToNat32(Prim.nat8ToNat(x[3]));

///
/// Most operations are available as built-in operators (e.g. `1 + 1`).
import Nat "Nat";
import Nat8 "Nat8";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this module actually used?

@Brycewetzel
Copy link

still ok?

@ggreif ggreif force-pushed the master branch 2 times, most recently from d52aecd to 08507fc Compare October 21, 2022 12:22
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.

4 participants