-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
I was fiddling around with the new INumber<TSelf> interface, but I found something that is definitely out-of-place.
INumber<TSelf> inherits IUnaryNegationOperators<TSelf, TSelf> which makes you implement this operator:
static abstract TSelf operator -(TSelf value);At first sight it looks completely fine, but this is actually NOT fine for unsigned numbers. There's a really valid reason why uint returns long when you use the unary minus operator on it, or why ushort and byte returns int. And for this same reason, this interface shouldn't be part of INumber<TSelf> interface.
Suggestion
Move IUnaryNegationOperators<TSelf, TSelf> from INumber<TSelf> to ISignedNumber<TSelf>
In this way, IUnsignedNumber<TSelf> won't inherit such interface just to return a wrong data type or throw an exception.
Drawbacks
Breaking change but we are in previews so we're still in time, I personally consider it very necessary until its too late.
Another drawback is that now you have to implement IUnaryNegationOperators<TSelf, TResult> if you implement IUnsignedNumber<TSelf>, but that's how it should be.