diff --git a/DotMP/Atomic.cs b/DotMP/Atomic.cs index cef47c2f..7c7648f1 100644 --- a/DotMP/Atomic.cs +++ b/DotMP/Atomic.cs @@ -113,8 +113,8 @@ public static uint Add(ref uint target, uint value) /// The new value stored as a result of the operation. public static uint Sub(ref uint target, uint value) { - int neg = -(int)value; - return Interlocked.Add(ref target, Unsafe.As(ref neg)); + uint neg = ~value + 1; + return Interlocked.Add(ref target, neg); } /// @@ -246,8 +246,8 @@ public static ulong Add(ref ulong target, ulong value) /// The new value stored as a result of the operation. public static ulong Sub(ref ulong target, ulong value) { - long neg = -(long)value; - return Interlocked.Add(ref target, Unsafe.As(ref neg)); + ulong neg = ~value + 1; + return Interlocked.Add(ref target, neg); } ///