✅ Code highlighting issue in Rider with Int128 and UInt128 types
Putting the new 128-bit integer classes to use which implement ISignedNumber and IUnsignedNumber. Both of those interfaces implement INumberBase and that implements IAdditionOperators. Here is the code of both UInt128 and Int128 with their operator + implementations:
public static UInt128 operator +(UInt128 left, UInt128 right) { // For unsigned addition, we can detect overflow by checking `(x + y) < x` // This gives us the carry to add to upper to compute the correct result ulong lower = left._lower + right._lower; ulong carry = (lower < left._lower) ? 1UL : 0UL; ulong upper = left._upper + right._upper + carry; return new UInt128(upper, lower); }
public static UInt128 operator +(UInt128 left, UInt128 right) { // For unsigned addition, we can detect overflow by checking `(x + y) < x` // This gives us the carry to add to upper to compute the correct result ulong lower = left._lower + right._lower; ulong carry = (lower < left._lower) ? 1UL : 0UL; ulong upper = left._upper + right._upper + carry; return new UInt128(upper, lower); }
public static Int128 operator +(Int128 left, Int128 right) { // For unsigned addition, we can detect overflow by checking `(x + y) < x` // This gives us the carry to add to upper to compute the correct result ulong lower = left._lower + right._lower; ulong carry = (lower < left._lower) ? 1UL : 0UL; ulong upper = left._upper + right._upper + carry; return new Int128(upper, lower); }
public static Int128 operator +(Int128 left, Int128 right) { // For unsigned addition, we can detect overflow by checking `(x + y) < x` // This gives us the carry to add to upper to compute the correct result ulong lower = left._lower + right._lower; ulong carry = (lower < left._lower) ? 1UL : 0UL; ulong upper = left._upper + right._upper + carry; return new Int128(upper, lower); }
How come Rider keeps telling me these types are incapable of any sort of operation? The code runs fine but is there a way to fix this inconvenience? Or at the least, disable the check here?
I have already changed all projects to target .NET 7.0 and the solution's .NET SDK is 7.0. I also invalidated the caches
Similar Threads
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
C
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.