diff --git a/src/Math/Fixed/Fix64.cs b/src/Math/Fixed/Fix64.cs index a0d4239d..119d5832 100644 --- a/src/Math/Fixed/Fix64.cs +++ b/src/Math/Fixed/Fix64.cs @@ -52,6 +52,14 @@ namespace MoonWorks.Math.Fixed return new Fix64(numerator) / new Fix64(denominator); } + /// + /// Gets the fractional component of this Fix64 value. + /// + public static Fix64 Fractional(Fix64 number) + { + return new Fix64(number.RawValue & 0x00000000FFFFFFFF); + } + public static Fix64 Random(System.Random random, int max) { var fractional = random.Next(); @@ -182,6 +190,14 @@ namespace MoonWorks.Math.Fixed return value1 + (value2 - value1) * amount; } + /// + /// Rescales a value within a given range to a new range. + /// + public static Fix64 Normalize(Fix64 value, Fix64 min, Fix64 max, Fix64 newMin, Fix64 newMax) + { + return ((value - min) * (newMax - newMin)) / (max - min) + newMin; + } + // Trigonometry functions ///