| | | 1 | | //======================================================================= |
| | | 2 | | // Fixed64.Operators.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace FixedMathSharp; |
| | | 12 | | |
| | | 13 | | public partial struct Fixed64 |
| | | 14 | | { |
| | | 15 | | #region Arithmetic Operators |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Adds two Fixed64 numbers, with saturating behavior in case of overflow. |
| | | 19 | | /// </summary> |
| | | 20 | | public static Fixed64 operator +(Fixed64 x, Fixed64 y) |
| | | 21 | | { |
| | 23443 | 22 | | long xl = x.m_rawValue; |
| | 23443 | 23 | | long yl = y.m_rawValue; |
| | 23443 | 24 | | long sum = xl + yl; |
| | | 25 | | // Check for overflow, if signs of operands are equal and signs of sum and x are different |
| | 23443 | 26 | | if (((~(xl ^ yl) & (xl ^ sum)) & FixedMath.MIN_VALUE_L) != 0) |
| | 2 | 27 | | sum = xl > 0 ? FixedMath.MAX_VALUE_L : FixedMath.MIN_VALUE_L; |
| | 23443 | 28 | | return new Fixed64(sum); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Adds an int to a Fixed64, with saturating behavior in case of overflow. |
| | | 33 | | /// </summary> |
| | | 34 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 24 | 35 | | public static Fixed64 operator +(Fixed64 x, int y) => x + new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I); |
| | | 36 | | |
| | | 37 | | /// <inheritdoc cref="operator +(Fixed64, int)" /> |
| | | 38 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 39 | | public static Fixed64 operator +(int x, Fixed64 y) => y + x; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Subtracts one Fixed64 number from another, with saturating behavior in case of overflow. |
| | | 43 | | /// </summary> |
| | | 44 | | public static Fixed64 operator -(Fixed64 x, Fixed64 y) |
| | | 45 | | { |
| | 15937 | 46 | | long xl = x.m_rawValue; |
| | 15937 | 47 | | long yl = y.m_rawValue; |
| | 15937 | 48 | | long diff = xl - yl; |
| | | 49 | | // Check for overflow, if signs of operands are different and signs of sum and x are different |
| | 15937 | 50 | | if ((((xl ^ yl) & (xl ^ diff)) & FixedMath.MIN_VALUE_L) != 0) |
| | 2 | 51 | | diff = xl < 0 ? FixedMath.MIN_VALUE_L : FixedMath.MAX_VALUE_L; |
| | 15937 | 52 | | return new Fixed64(diff); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Subtracts an int from a Fixed64, with saturating behavior in case of overflow. |
| | | 57 | | /// </summary> |
| | | 58 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 59 | | public static Fixed64 operator -(Fixed64 x, int y) => |
| | 10 | 60 | | x - new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I); |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Subtracts a Fixed64 from an int, with saturating behavior in case of overflow. |
| | | 64 | | /// </summary> |
| | | 65 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 66 | | public static Fixed64 operator -(int x, Fixed64 y) => |
| | 10 | 67 | | new Fixed64((long)x << FixedMath.SHIFT_AMOUNT_I) - y; |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Multiplies two Fixed64 numbers, handling overflow and rounding. |
| | | 71 | | /// </summary> |
| | | 72 | | /// <summary> |
| | | 73 | | /// Multiplies two Fixed64 numbers using full-width 128-bit intermediate precision |
| | | 74 | | /// and round-half-to-even semantics on the discarded fractional bits. |
| | | 75 | | /// </summary> |
| | | 76 | | public static Fixed64 operator *(Fixed64 x, Fixed64 y) |
| | | 77 | | { |
| | 54427 | 78 | | long xl = x.m_rawValue; |
| | 54427 | 79 | | long yl = y.m_rawValue; |
| | | 80 | | |
| | 54427 | 81 | | int shift = FixedMath.SHIFT_AMOUNT_I; |
| | | 82 | | |
| | | 83 | | // Determine sign of the final result. |
| | 54427 | 84 | | bool negative = ((xl ^ yl) < 0); |
| | | 85 | | |
| | | 86 | | // Convert to unsigned magnitudes safely, including long.MinValue. |
| | 54427 | 87 | | ulong ax = AbsToUInt64(xl); |
| | 54427 | 88 | | ulong ay = AbsToUInt64(yl); |
| | | 89 | | |
| | | 90 | | // Compute exact 128-bit unsigned product: (hi << 64) | lo |
| | 54427 | 91 | | Multiply64To128(ax, ay, out ulong hi, out ulong lo); |
| | | 92 | | |
| | | 93 | | // Shift-right with round-half-to-even using the FULL discarded remainder. |
| | 54427 | 94 | | ulong magnitude = ShiftRightRoundedToEven(hi, lo, shift, out bool roundedOverflow); |
| | | 95 | | |
| | | 96 | | // If rounding overflowed the shifted magnitude, carry it into saturation handling. |
| | 54427 | 97 | | if (!negative) |
| | | 98 | | { |
| | 40737 | 99 | | if (roundedOverflow || magnitude > long.MaxValue) |
| | 5 | 100 | | return new Fixed64(FixedMath.MAX_VALUE_L); |
| | | 101 | | |
| | 40732 | 102 | | return new Fixed64((long)magnitude); |
| | | 103 | | } |
| | | 104 | | else |
| | | 105 | | { |
| | | 106 | | // For negative results, magnitude may be exactly 2^63, which maps to long.MinValue. |
| | | 107 | | const ulong minValueMagnitude = 0x8000000000000000UL; |
| | | 108 | | |
| | 13690 | 109 | | if (roundedOverflow || magnitude > minValueMagnitude) |
| | 2 | 110 | | return new Fixed64(FixedMath.MIN_VALUE_L); |
| | | 111 | | |
| | 13688 | 112 | | if (magnitude == minValueMagnitude) |
| | 1 | 113 | | return new Fixed64(FixedMath.MIN_VALUE_L); |
| | | 114 | | |
| | 13687 | 115 | | return new Fixed64(-(long)magnitude); |
| | | 116 | | } |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | /// <summary> |
| | | 120 | | /// Returns the absolute value of a signed 64-bit integer as an unsigned 64-bit magnitude, |
| | | 121 | | /// safely handling long.MinValue. |
| | | 122 | | /// </summary> |
| | | 123 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 124 | | private static ulong AbsToUInt64(long value) |
| | | 125 | | { |
| | 108854 | 126 | | return value < 0 |
| | 108854 | 127 | | ? unchecked((ulong)(~value + 1)) |
| | 108854 | 128 | | : (ulong)value; |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | /// <summary> |
| | | 132 | | /// Computes the exact unsigned 128-bit product of two 64-bit unsigned integers. |
| | | 133 | | /// The result is returned as hi:lo, where product = (hi << 64) | lo. |
| | | 134 | | /// </summary> |
| | | 135 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 136 | | private static void Multiply64To128(ulong a, ulong b, out ulong hi, out ulong lo) |
| | | 137 | | { |
| | 54427 | 138 | | ulong aLo = (uint)a; |
| | 54427 | 139 | | ulong aHi = a >> 32; |
| | 54427 | 140 | | ulong bLo = (uint)b; |
| | 54427 | 141 | | ulong bHi = b >> 32; |
| | | 142 | | |
| | 54427 | 143 | | ulong p0 = aLo * bLo; |
| | 54427 | 144 | | ulong p1 = aLo * bHi; |
| | 54427 | 145 | | ulong p2 = aHi * bLo; |
| | 54427 | 146 | | ulong p3 = aHi * bHi; |
| | | 147 | | |
| | 54427 | 148 | | ulong middle = (p0 >> 32) + (uint)p1 + (uint)p2; |
| | | 149 | | |
| | 54427 | 150 | | lo = (p0 & 0xFFFFFFFFUL) | (middle << 32); |
| | 54427 | 151 | | hi = p3 + (p1 >> 32) + (p2 >> 32) + (middle >> 32); |
| | 54427 | 152 | | } |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Shifts the unsigned 128-bit value (hi:lo) right by <paramref name="shift"/> bits, |
| | | 156 | | /// applying round-half-to-even to the discarded bits. |
| | | 157 | | /// </summary> |
| | | 158 | | /// <param name="hi">Upper 64 bits of the 128-bit value.</param> |
| | | 159 | | /// <param name="lo">Lower 64 bits of the 128-bit value.</param> |
| | | 160 | | /// <param name="shift">Number of bits to shift right. Must be in the range 1..63.</param> |
| | | 161 | | /// <param name="overflowed"> |
| | | 162 | | /// True if the shifted or rounded result exceeded 64 bits. |
| | | 163 | | /// </param> |
| | | 164 | | /// <returns> |
| | | 165 | | /// The rounded 64-bit result of ((hi:lo) >> shift). |
| | | 166 | | /// </returns> |
| | | 167 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 168 | | private static ulong ShiftRightRoundedToEven(ulong hi, ulong lo, int shift, out bool overflowed) |
| | | 169 | | { |
| | | 170 | | // Preconditions: 1 <= shift <= 63 |
| | | 171 | | |
| | | 172 | | // Bits above the low 64 result bits must be preserved as saturation state |
| | | 173 | | // before the lower projection can wrap back into range. |
| | 54427 | 174 | | overflowed = (hi >> shift) != 0UL; |
| | | 175 | | |
| | | 176 | | // Integer part after shifting right by 'shift': |
| | | 177 | | // result = ((hi << (64 - shift)) | (lo >> shift)) |
| | 54427 | 178 | | ulong result = (hi << (64 - shift)) | (lo >> shift); |
| | | 179 | | |
| | | 180 | | // Discarded remainder bits are the low 'shift' bits of lo. |
| | 54427 | 181 | | ulong remainderMask = (1UL << shift) - 1UL; |
| | 54427 | 182 | | ulong remainder = lo & remainderMask; |
| | | 183 | | |
| | | 184 | | // Halfway value among the discarded bits. |
| | 54427 | 185 | | ulong half = 1UL << (shift - 1); |
| | | 186 | | |
| | | 187 | | // Round-half-to-even: |
| | | 188 | | // - round up if remainder > half |
| | | 189 | | // - if exactly half, round so final result is even |
| | 54427 | 190 | | bool shouldRoundUp = |
| | 54427 | 191 | | remainder > half || |
| | 54427 | 192 | | (remainder == half && (result & 1UL) != 0); |
| | | 193 | | |
| | 54427 | 194 | | if (shouldRoundUp) |
| | | 195 | | { |
| | 2686 | 196 | | ulong incremented = result + 1UL; |
| | 2686 | 197 | | overflowed |= incremented < result; |
| | 2686 | 198 | | result = incremented; |
| | | 199 | | } |
| | | 200 | | |
| | 54427 | 201 | | return result; |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | /// <summary> |
| | | 205 | | /// Multiplies a Fixed64 by an integer, with overflow handling. |
| | | 206 | | /// </summary> |
| | | 207 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 208 | | public static Fixed64 operator *(Fixed64 x, int y) => |
| | 1528 | 209 | | x * new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I); |
| | | 210 | | |
| | | 211 | | /// <inheritdoc cref="operator *(Fixed64, int)" /> |
| | | 212 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 56 | 213 | | public static Fixed64 operator *(int x, Fixed64 y) => y * x; |
| | | 214 | | |
| | | 215 | | /// <summary> |
| | | 216 | | /// Divides one Fixed64 number by another, handling division by zero and overflow. |
| | | 217 | | /// </summary> |
| | | 218 | | public static Fixed64 operator /(Fixed64 x, Fixed64 y) |
| | | 219 | | { |
| | 5542 | 220 | | long xl = x.m_rawValue; |
| | 5542 | 221 | | long yl = y.m_rawValue; |
| | | 222 | | |
| | 5542 | 223 | | if (yl == 0) |
| | 3 | 224 | | throw new DivideByZeroException($"Attempted to divide {x} by zero."); |
| | | 225 | | |
| | 5539 | 226 | | ulong remainder = (ulong)(xl < 0 ? -xl : xl); |
| | 5539 | 227 | | ulong divider = (ulong)(yl < 0 ? -yl : yl); |
| | 5539 | 228 | | ulong quotient = 0UL; |
| | 5539 | 229 | | int bitPos = FixedMath.SHIFT_AMOUNT_I + 1; |
| | | 230 | | |
| | | 231 | | // If the divider is divisible by 2^n, take advantage of it. |
| | 45346 | 232 | | while ((divider & 0xF) == 0 && bitPos >= 4) |
| | | 233 | | { |
| | 39807 | 234 | | divider >>= 4; |
| | 39807 | 235 | | bitPos -= 4; |
| | | 236 | | } |
| | | 237 | | |
| | 10863 | 238 | | while (remainder != 0 && bitPos >= 0) |
| | | 239 | | { |
| | 5326 | 240 | | int shift = CountLeadingZeroes(remainder); |
| | 5326 | 241 | | if (shift > bitPos) |
| | 4880 | 242 | | shift = bitPos; |
| | | 243 | | |
| | 5326 | 244 | | remainder <<= shift; |
| | 5326 | 245 | | bitPos -= shift; |
| | | 246 | | |
| | 5326 | 247 | | ulong div = remainder / divider; |
| | 5326 | 248 | | remainder %= divider; |
| | 5326 | 249 | | quotient += div << bitPos; |
| | | 250 | | |
| | | 251 | | // Detect overflow |
| | 5326 | 252 | | if ((div & ~(0xFFFFFFFFFFFFFFFF >> bitPos)) != 0) |
| | 2 | 253 | | return ((xl ^ yl) & FixedMath.MIN_VALUE_L) == 0 |
| | 2 | 254 | | ? new Fixed64(FixedMath.MAX_VALUE_L) |
| | 2 | 255 | | : new Fixed64(FixedMath.MIN_VALUE_L); |
| | | 256 | | |
| | 5324 | 257 | | remainder <<= 1; |
| | 5324 | 258 | | --bitPos; |
| | | 259 | | } |
| | | 260 | | |
| | | 261 | | // Rounding logic: "Round half to even" or "Banker's rounding" |
| | 5537 | 262 | | if ((quotient & 0x1) != 0) |
| | 390 | 263 | | quotient += 1; |
| | | 264 | | |
| | 5537 | 265 | | long result = (long)(quotient >> 1); |
| | 5537 | 266 | | if (((xl ^ yl) & FixedMath.MIN_VALUE_L) != 0) |
| | 677 | 267 | | result = -result; |
| | | 268 | | |
| | 5537 | 269 | | return new Fixed64(result); |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | /// <summary> |
| | | 273 | | /// Divides a Fixed64 by an integer, handling division by zero and overflow. |
| | | 274 | | /// </summary> |
| | | 275 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 276 | | public static Fixed64 operator /(Fixed64 x, int y) => |
| | 811 | 277 | | x / new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I); |
| | | 278 | | |
| | | 279 | | /// <summary> |
| | | 280 | | /// Divides an integer by a Fixed64, handling division by zero and overflow. |
| | | 281 | | /// </summary> |
| | | 282 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 283 | | public static Fixed64 operator /(int y, Fixed64 x) => |
| | 1 | 284 | | new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I) / x; |
| | | 285 | | |
| | | 286 | | /// <summary> |
| | | 287 | | /// Computes the remainder of division of one Fixed64 number by another. |
| | | 288 | | /// </summary> |
| | | 289 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 290 | | public static Fixed64 operator %(Fixed64 x, Fixed64 y) |
| | | 291 | | { |
| | 284 | 292 | | if (x.m_rawValue == FixedMath.MIN_VALUE_L && y.m_rawValue == -1) |
| | 1 | 293 | | return Zero; |
| | 283 | 294 | | return new Fixed64(x.m_rawValue % y.m_rawValue); |
| | | 295 | | } |
| | | 296 | | |
| | | 297 | | /// <summary> |
| | | 298 | | /// Computes the remainder of division of a Fixed64 by an int. |
| | | 299 | | /// </summary> |
| | | 300 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 301 | | public static Fixed64 operator %(Fixed64 x, int y) => x % new Fixed64((long)y << FixedMath.SHIFT_AMOUNT_I); |
| | | 302 | | |
| | | 303 | | /// <summary> |
| | | 304 | | /// Computes the remainder of division of an int by a Fixed64. |
| | | 305 | | /// </summary> |
| | | 306 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 307 | | public static Fixed64 operator %(int x, Fixed64 y) => new Fixed64((long)x << FixedMath.SHIFT_AMOUNT_I) % y; |
| | | 308 | | |
| | | 309 | | /// <summary> |
| | | 310 | | /// Unary negation operator. |
| | | 311 | | /// </summary> |
| | | 312 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 313 | | public static Fixed64 operator -(Fixed64 x) => |
| | 4036 | 314 | | x.m_rawValue == FixedMath.MIN_VALUE_L |
| | 4036 | 315 | | ? new Fixed64(FixedMath.MAX_VALUE_L) |
| | 4036 | 316 | | : new Fixed64(-x.m_rawValue); |
| | | 317 | | |
| | | 318 | | /// <summary> |
| | | 319 | | /// Increments a Fixed64 number by one, with saturating behavior in case of overflow. |
| | | 320 | | /// </summary> |
| | | 321 | | /// <param name="a">The Fixed64 number to increment.</param> |
| | | 322 | | /// <returns>The incremented Fixed64 number.</returns> |
| | | 323 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 324 | | public static Fixed64 operator ++(Fixed64 a) => a + One; |
| | | 325 | | |
| | | 326 | | /// <summary> |
| | | 327 | | /// Decrements a Fixed64 number by one, with saturating behavior in case of overflow. |
| | | 328 | | /// </summary> |
| | | 329 | | /// <param name="a">The Fixed64 number to decrement.</param> |
| | | 330 | | /// <returns>The decremented Fixed64 number.</returns> |
| | | 331 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2 | 332 | | public static Fixed64 operator --(Fixed64 a) => a - One; |
| | | 333 | | |
| | | 334 | | /// <summary> |
| | | 335 | | /// Bitwise left shift operator. |
| | | 336 | | /// </summary> |
| | | 337 | | /// <param name="a">Operand to shift.</param> |
| | | 338 | | /// <param name="shift">Number of bits to shift.</param> |
| | | 339 | | /// <returns>The shifted value.</returns> |
| | | 340 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 341 | | public static Fixed64 operator <<(Fixed64 a, int shift) => new(a.m_rawValue << shift); |
| | | 342 | | |
| | | 343 | | /// <summary> |
| | | 344 | | /// Bitwise right shift operator. |
| | | 345 | | /// </summary> |
| | | 346 | | /// <param name="a">Operand to shift.</param> |
| | | 347 | | /// <param name="shift">Number of bits to shift.</param> |
| | | 348 | | /// <returns>The shifted value.</returns> |
| | | 349 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 350 | | public static Fixed64 operator >>(Fixed64 a, int shift) => new(a.m_rawValue >> shift); |
| | | 351 | | |
| | | 352 | | #endregion |
| | | 353 | | #region Comparison Operators |
| | | 354 | | |
| | | 355 | | /// <summary> |
| | | 356 | | /// Determines whether one Fixed64 is greater than another. |
| | | 357 | | /// </summary> |
| | | 358 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 7156 | 359 | | public static bool operator >(Fixed64 x, Fixed64 y) => x.m_rawValue > y.m_rawValue; |
| | | 360 | | |
| | | 361 | | /// <summary> |
| | | 362 | | /// Determines whether a Fixed64 is greater than an integer. |
| | | 363 | | /// </summary> |
| | | 364 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 365 | | public static bool operator >(Fixed64 x, int y) => x.m_rawValue > (long)y << FixedMath.SHIFT_AMOUNT_I; |
| | | 366 | | |
| | | 367 | | /// <summary> |
| | | 368 | | /// Determines whether an integer is greater than a Fixed64. |
| | | 369 | | /// </summary> |
| | | 370 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 371 | | public static bool operator >(int y, Fixed64 x) => (long)y << FixedMath.SHIFT_AMOUNT_I > x.m_rawValue; |
| | | 372 | | |
| | | 373 | | /// <summary> |
| | | 374 | | /// Determines whether one Fixed64 is less than another. |
| | | 375 | | /// </summary> |
| | | 376 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 18969 | 377 | | public static bool operator <(Fixed64 x, Fixed64 y) => x.m_rawValue < y.m_rawValue; |
| | | 378 | | |
| | | 379 | | /// <summary> |
| | | 380 | | /// Determines whether one Fixed64 is less than an integer. |
| | | 381 | | /// </summary> |
| | | 382 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 383 | | public static bool operator <(Fixed64 x, int y) => x.m_rawValue < (long)y << FixedMath.SHIFT_AMOUNT_I; |
| | | 384 | | |
| | | 385 | | /// <summary> |
| | | 386 | | /// Determines whether an integer is less than a Fixed64. |
| | | 387 | | /// </summary> |
| | | 388 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 389 | | public static bool operator <(int y, Fixed64 x) => (long)y << FixedMath.SHIFT_AMOUNT_I < x.m_rawValue; |
| | | 390 | | |
| | | 391 | | /// <summary> |
| | | 392 | | /// Determines whether one Fixed64 is greater than or equal to another. |
| | | 393 | | /// </summary> |
| | | 394 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 15142 | 395 | | public static bool operator >=(Fixed64 x, Fixed64 y) => x.m_rawValue >= y.m_rawValue; |
| | | 396 | | |
| | | 397 | | /// <summary> |
| | | 398 | | /// Determines whether Fixed64 is greater than or equal to an integer. |
| | | 399 | | /// </summary> |
| | | 400 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 401 | | public static bool operator >=(Fixed64 x, int y) => x.m_rawValue >= (long)y << FixedMath.SHIFT_AMOUNT_I; |
| | | 402 | | |
| | | 403 | | /// <summary> |
| | | 404 | | /// Determines whether an integer is greater than or equal to a Fixed64. |
| | | 405 | | /// </summary> |
| | | 406 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 407 | | public static bool operator >=(int y, Fixed64 x) => (long)y << FixedMath.SHIFT_AMOUNT_I >= x.m_rawValue; |
| | | 408 | | |
| | | 409 | | /// <summary> |
| | | 410 | | /// Determines whether one Fixed64 is less than or equal to another. |
| | | 411 | | /// </summary> |
| | | 412 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 7783 | 413 | | public static bool operator <=(Fixed64 x, Fixed64 y) => x.m_rawValue <= y.m_rawValue; |
| | | 414 | | |
| | | 415 | | /// <summary> |
| | | 416 | | /// Determines whether a Fixed64 is less than or equal to an integer. |
| | | 417 | | /// </summary> |
| | | 418 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 419 | | public static bool operator <=(Fixed64 x, int y) => x.m_rawValue <= (long)y << FixedMath.SHIFT_AMOUNT_I; |
| | | 420 | | |
| | | 421 | | /// <summary> |
| | | 422 | | /// Determines whether an integer is less than or equal to a Fixed64. |
| | | 423 | | /// </summary> |
| | | 424 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 425 | | public static bool operator <=(int y, Fixed64 x) => (long)y << FixedMath.SHIFT_AMOUNT_I <= x.m_rawValue; |
| | | 426 | | |
| | | 427 | | /// <summary> |
| | | 428 | | /// Determines whether two Fixed64 instances are equal. |
| | | 429 | | /// </summary> |
| | | 430 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 9207 | 431 | | public static bool operator ==(Fixed64 left, Fixed64 right) => left.Equals(right); |
| | | 432 | | |
| | | 433 | | /// <summary> |
| | | 434 | | /// Determines whether a Fixed64 instance is equal to an integer. |
| | | 435 | | /// </summary> |
| | | 436 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 437 | | public static bool operator ==(Fixed64 left, int right) => left.m_rawValue == (long)right << FixedMath.SHIFT_AMOUNT_ |
| | | 438 | | |
| | | 439 | | /// <summary> |
| | | 440 | | /// Determines whether an integer is equal to a Fixed64 instance. |
| | | 441 | | /// </summary> |
| | | 442 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 443 | | public static bool operator ==(int left, Fixed64 right) => (long)left << FixedMath.SHIFT_AMOUNT_I == right.m_rawValu |
| | | 444 | | |
| | | 445 | | /// <summary> |
| | | 446 | | /// Determines whether two Fixed64 instances are not equal. |
| | | 447 | | /// </summary> |
| | | 448 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 426 | 449 | | public static bool operator !=(Fixed64 left, Fixed64 right) => !left.Equals(right); |
| | | 450 | | |
| | | 451 | | /// <summary> |
| | | 452 | | /// Determines whether a Fixed64 instance is not equal to an integer. |
| | | 453 | | /// </summary> |
| | | 454 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 455 | | public static bool operator !=(Fixed64 left, int right) => left.m_rawValue != (long)right << FixedMath.SHIFT_AMOUNT_ |
| | | 456 | | |
| | | 457 | | /// <summary> |
| | | 458 | | /// Determines whether an integer is equal to a Fixed64 instance. |
| | | 459 | | /// </summary> |
| | | 460 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 461 | | public static bool operator !=(int left, Fixed64 right) => (long)left << FixedMath.SHIFT_AMOUNT_I != right.m_rawValu |
| | | 462 | | |
| | | 463 | | #endregion |
| | | 464 | | } |