saxbophone / arby

Arbitrary precision arithmetic in C++, even at compile-time
https://saxbophone.com/arby/
Mozilla Public License 2.0
8 stars 1 forks source link

Pedantic: Extend byte_length()/bit_length() to support systems where CHAR_BIT is not 8 #119

Open saxbophone opened 2 years ago

saxbophone commented 2 years ago

Current code assumes 8-bit (a reasonable assumption):

https://github.com/saxbophone/arby/blob/8f9b0bd40e82fd6a558eb71cb53091b628dbaee9/arby/include/arby/Nat.hpp#L827-L840

But we can make this portable without compromising the behaviour on the vast majority of systems where CHAR_BIT=8 by using CHAR_BIT in place of 8 and PRIVATE::exp(2, CHAR_BIT) in place of 256

This should support any systems where CHAR_BIT > 8. The rest of the code should be checked over for any other places where byte = 8-bit is assumed.