From a427b7951036bc745c0f7c3002141e5991bef96e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 16 Aug 2022 18:24:34 -0700 Subject: [PATCH] add Fix64-int arithmetic --- src/Math/Fixed/Fix64.cs | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Math/Fixed/Fix64.cs b/src/Math/Fixed/Fix64.cs index 44b47123..310d43d6 100644 --- a/src/Math/Fixed/Fix64.cs +++ b/src/Math/Fixed/Fix64.cs @@ -531,6 +531,16 @@ namespace MoonWorks.Math.Fixed return new Fix64(sum); } + public static Fix64 operator +(Fix64 x, int y) + { + return x + new Fix64(y); + } + + public static Fix64 operator +(int x, Fix64 y) + { + return new Fix64(x) + y; + } + public static Fix64 operator -(Fix64 x, Fix64 y) { var xl = x.RawValue; @@ -544,6 +554,16 @@ namespace MoonWorks.Math.Fixed return new Fix64(diff); } + public static Fix64 operator -(Fix64 x, int y) + { + return x - new Fix64(y); + } + + public static Fix64 operator -(int x, Fix64 y) + { + return new Fix64(x) - y; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Fix64 FastSub(Fix64 x, Fix64 y) { @@ -668,6 +688,16 @@ namespace MoonWorks.Math.Fixed return result; } + public static Fix64 operator *(Fix64 x, int y) + { + return x * new Fix64(y); + } + + public static Fix64 operator *(int x, Fix64 y) + { + return new Fix64(x) * y; + } + public static Fix64 operator /(Fix64 x, Fix64 y) { var xl = x.RawValue; @@ -726,6 +756,16 @@ namespace MoonWorks.Math.Fixed return new Fix64(result); } + public static Fix64 operator /(Fix64 x, int y) + { + return x / new Fix64(y); + } + + public static Fix64 operator /(int x, Fix64 y) + { + return new Fix64(x) / y; + } + public static Fix64 operator %(Fix64 x, Fix64 y) { return new Fix64( @@ -734,6 +774,16 @@ namespace MoonWorks.Math.Fixed x.RawValue % y.RawValue); } + public static Fix64 operator %(Fix64 x, int y) + { + return x % new Fix64(y); + } + + public static Fix64 operator %(int x, Fix64 y) + { + return new Fix64(x) % y; + } + public static Fix64 operator -(Fix64 x) { return x.RawValue == MIN_VALUE ? MaxValue : new Fix64(-x.RawValue);