bigints icon indicating copy to clipboard operation
bigints copied to clipboard

Add toBytes proc

Open ehmry opened this issue 2 years ago • 9 comments

  • Export isNegative and isZero because it is easier to export here than to reimplement downstream.
  • Add toBytes proc for serializing. This is used by the CBOR package. Also easier to implement here than downstream.
  • Rename the tests/tliterals.nim to comply with Nimble standards. Not all tools are using nimble test for testing, some rely only on Nimble standards.

ehmry avatar Jun 19 '23 10:06 ehmry

Thanks for your contribution! The algorithm looks fine to me. – Could you add tests for the toBytes procedure? – Could you add the corresponding fromBytes procedure? I believe that the tliterals was renamed literals as to not run these tests. You might want to check the log for this specific file.

dlesnoff avatar Jun 19 '23 11:06 dlesnoff

I­ pushed a test for toBytes. I will push fromBytes soon.

ehmry avatar Jun 21 '23 09:06 ehmry

Now with fromBytes and a test of random serializations.

ehmry avatar Jun 21 '23 10:06 ehmry

I'm against exporting isNegative and isZero. I think the better solution would be to support comparing with ints, then we can just use < 0 and == 0 (see #132).

konsumlamm avatar Jul 22 '23 20:07 konsumlamm

I'm against exporting isNegative and isZero. I think the better solution would be to support comparing with ints, then we can just use < 0 and == 0 (see #132).

That would be adding more code to do something that is already implemented.

ehmry avatar Jul 23 '23 07:07 ehmry

I'm against exporting isNegative and isZero. I think the better solution would be to support comparing with ints, then we can just use < 0 and == 0 (see #132).

That would be adding more code to do something that is already implemented.

Yes, but it's also uglier imo.

konsumlamm avatar Jul 23 '23 11:07 konsumlamm

I am for exporting isNegative only and implement equality with integers. Comparing with integers and fetching a boolean flag are two different things.

dlesnoff avatar Jul 24 '23 20:07 dlesnoff

Note that isNegative really means "is less than or equal to zero", as 0 can also have isNegative set.

konsumlamm avatar Jul 24 '23 20:07 konsumlamm

Thanks for the reminder.

dlesnoff avatar Jul 24 '23 21:07 dlesnoff