From bb0b6daa91d47fc1a8c8bd62d6f786b3027d443d Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 7 Jun 2022 17:01:44 -0700 Subject: [PATCH] Fix64.Fractional --- src/Math/Fixed/Fix64.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 ///