Merge pull request #586 from Noggog/percent-fix

Percent.One bugfix
This commit is contained in:
Timothy Baldridge 2020-02-28 08:16:37 -07:00 committed by GitHub
commit d1d492e76c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,11 +6,11 @@ namespace Wabbajack.Common
{
public struct Percent : IComparable, IEquatable<Percent>
{
public static readonly Percent One = new Percent(1);
public static readonly Percent Zero = new Percent(0);
public static readonly Percent One = new Percent(1d);
public static readonly Percent Zero = new Percent(0d);
public readonly double Value;
public Percent Inverse => new Percent(1 - this.Value, check: false);
public Percent Inverse => new Percent(1d - this.Value, check: false);
private Percent(double d, bool check)
{
@ -24,7 +24,8 @@ namespace Wabbajack.Common
}
}
public Percent(long max, long current) : this((double)current / max)
public Percent(long max, long current)
: this((double)current / max)
{
}
@ -34,22 +35,6 @@ namespace Wabbajack.Common
{
}
public Percent(int i)
{
if (i < 0)
{
Value = 0;
}
else if (i > 100)
{
Value = 1;
}
else
{
Value = i / 100d;
}
}
public static bool InRange(double d)
{
return d >= 0 || d <= 1;