ace/Source/ACE.Common/Extensions/FloatExtensions.cs
gmriggs c90baf8a80
update recipes to use mutation scripts (#3593)
* update recipes to use mutation scripts

* additional refactoring

* .

* update proficiency code

* foolproof salvage code is still needed until recipes are added

* add comment

* add rare foolproof

* update sandstone

* adding sandstone mutation

* update RecipeManager_New recipes for foolproof salvage

* add RecipeManager_New caching

* finish removing ClearRecipe()

* update comments

* update defense imbues to include shields, as per base recipe

* improved UpdateObject server sync
2021-07-11 20:14:21 -04:00

32 lines
953 B
C#

using System;
namespace ACE.Common.Extensions
{
public static class FloatExtensions
{
public static int Round(this float num, int decimalPlaces = 0)
{
return (int)Math.Round(num, decimalPlaces, MidpointRounding.AwayFromZero);
}
public static int Round(this double num, int decimalPlaces = 0)
{
return (int)Math.Round(num, decimalPlaces, MidpointRounding.AwayFromZero);
}
public static float Truncate(this float num, int decimalPlaces)
{
var multiplier = Math.Pow(10, decimalPlaces);
return (float)(Math.Truncate(num * multiplier) / multiplier);
}
public static bool EpsilonEquals(this float num, float val/*, int decimalPlaces = 4*/)
{
//var epsilon = 1.0f / Math.Pow(10, decimalPlaces);
var epsilon = 0.0001f;
return Math.Abs(num - val) < epsilon;
}
}
}