Skip to content

Commit

Permalink
FixedMathExtensionsUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
frostiq committed May 25, 2019
1 parent 5aa7657 commit e398aca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.1</Version>
<Version>0.0.2</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ public static decimal ToDecimal(this BigInteger amount, int decimals = 0)
}

public static decimal ToDecimal(this BigInteger amount, uint decimals) => amount.ToDecimal((int) decimals);



#region Math

// basically stealing methods from here https://github.com/dapphub/ds-math/blob/49b38937c0c0b8af73b05f767a0af9d5e85a1e6c/src/math.sol
// wad has 18 precision points
// ray has 27 precision points

public static readonly BigInteger WadPrecision = new BigInteger(Math.Pow(10, 18));
public static readonly BigInteger RayPrecision = new BigInteger(Math.Pow(10, 27));

public static BigInteger WadMultiply(BigInteger x, BigInteger y)
public static BigInteger WadMultiply(this BigInteger x, BigInteger y)
{
return BigInteger.Divide(
BigInteger.Add(
Expand All @@ -44,7 +40,7 @@ public static BigInteger WadDivide(this BigInteger x, BigInteger y)
y);
}

public static BigInteger RayMultiply(BigInteger x, BigInteger y)
public static BigInteger RayMultiply(this BigInteger x, BigInteger y)
{
return BigInteger.Divide(
BigInteger.Add(
Expand All @@ -54,7 +50,7 @@ public static BigInteger RayMultiply(BigInteger x, BigInteger y)
}

// TODO: cover with unit tests
public static BigInteger RayPower(BigInteger x, BigInteger n)
public static BigInteger RayPower(this BigInteger x, BigInteger n)
{
var result = !BigInteger.Remainder(n, new BigInteger(2)).IsZero ? x : RayPrecision;

Expand All @@ -70,7 +66,5 @@ public static BigInteger RayPower(BigInteger x, BigInteger n)

return result;
}

#endregion
}
}

0 comments on commit e398aca

Please sign in to comment.