Fix64.Fractional

main
cosmonaut 2022-06-07 17:01:44 -07:00
parent 13519c3150
commit bb0b6daa91
1 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,14 @@ namespace MoonWorks.Math.Fixed
return new Fix64(numerator) / new Fix64(denominator);
}
/// <summary>
/// Gets the fractional component of this Fix64 value.
/// </summary>
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;
}
/// <summary>
/// Rescales a value within a given range to a new range.
/// </summary>
public static Fix64 Normalize(Fix64 value, Fix64 min, Fix64 max, Fix64 newMin, Fix64 newMax)
{
return ((value - min) * (newMax - newMin)) / (max - min) + newMin;
}
// Trigonometry functions
/// <summary>