-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement INumber
interface
#38
base: master
Are you sure you want to change the base?
Conversation
@@ -1650,6 +1654,16 @@ public static void Xor(in UInt256 a, in UInt256 b, out UInt256 res) | |||
? throw new OverflowException("Cannot convert UInt256 value to ulong.") | |||
: a.u0; | |||
|
|||
public static explicit operator Int128(in UInt256 a) => | |||
a.u2 > 0 || a.u3 > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also confirm a.u1's last bit does not overflow sign?
public static bool operator >=(UInt128 a, in UInt256 b) => !LessThan(a, in b); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static bool LessThan(in UInt256 a, int b) => b >= 0 && a.u3 == 0 && a.u2 == 0 && a.u1 == 0 && a.u0 < (ulong)b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if b==0
it seems to be false, so can be just b>0
I guess
private static bool LessThan(in UInt256 a, int b) => b >= 0 && a.u3 == 0 && a.u2 == 0 && a.u1 == 0 && a.u0 < (ulong)b; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static bool LessThan(int a, in UInt256 b) => b.u3 != 0 || b.u2 != 0 || b.u1 != 0 || (ulong)a < b.u0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be useful to compare a<0
, not sure
private static bool LessThan(int a, in UInt256 b) => b.u3 != 0 || b.u2 != 0 || b.u1 != 0 || (ulong)a < b.u0; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static bool LessThan(in UInt256 a, uint b) => b >= 0 && a.u3 == 0 && a.u2 == 0 && a.u1 == 0 && a.u0 < b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b is always >=0
Needs tests |
INumber
interface forInt256
andUInt256
typesInt128
andUInt128
support