lambdaworks icon indicating copy to clipboard operation
lambdaworks copied to clipboard

impl IsUnsignedInteger trait for u8 too

Open tdelabro opened this issue 2 years ago • 4 comments
trafficstars

in math/src/unsigned_integer/traits.rs

pub trait IsUnsignedInteger:
    Shr<usize, Output = Self>
    + BitAnd<Output = Self>
    + Eq
    + Ord
    + From<u16>
    + Copy
    + Display
    + Add<Self, Output = Self>
{
}

The From<u16> part prevents the trait from being impl for u8. Why is that? u8 is an unsigned integer too afterall? Can we change it and allow the trait to work with u8 too?

More broadly the trait name does not seem to correlate really well with the traits it requires: Shr, BitAnd, Add. It looks a bit arbitrary.

Also, this trait exists: https://docs.rs/num/latest/num/trait.Unsigned.html

tdelabro avatar Oct 05 '23 10:10 tdelabro

It could be improved a bit. The trait is expected to be used for custom Big Integers implementation. Creating a BigInt for an u8 seems a bit weird, but it's true it could be a improved. As for the operations it has, they are not arbitrary, they have the ones we need to build finite fields on top of it. More could be added

MauroToscano avatar Oct 05 '23 17:10 MauroToscano

So it's probably just the choice of name which is misleading. It is more an IsValidForFiniteField trait than an IsUnsignedInteger trait.

tdelabro avatar Oct 05 '23 22:10 tdelabro

can i take on this ?

mahmudsudo avatar Oct 20 '24 14:10 mahmudsudo