Skip to content

Commit

Permalink
BREAKING CHANGE: Changed the default Precision value to be 100 instea…
Browse files Browse the repository at this point in the history
…d of 5000.

Bumped major version number to 3000 to try and break the association of the version number with the date, and also to signify a significant change.
  • Loading branch information
AdamWhiteHat committed Oct 6, 2024
1 parent fcb46b8 commit ccc4193
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BigDecimal/BigDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public BigDecimal(Decimal value)
/// Sets the desired precision of all BigDecimal instances, in terms of the number of digits to the right of the decimal.
/// If AlwaysTruncate is set to true all operations are affected.
/// </summary>
public static Int32 Precision { get; set; } = 5000;
public static Int32 Precision { get; set; } = 100;

/// <summary>
/// Specifies whether the significant digits should be truncated to the given precision after each operation.
Expand Down
4 changes: 2 additions & 2 deletions BigDecimal/BigDecimal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</PropertyGroup>

<PropertyGroup>
<MajorVersion Condition=" '$(MajorVersion)' == '' ">2025</MajorVersion>
<MinorVersion Condition=" '$(MinorVersion)' == '' ">1007</MinorVersion>
<MajorVersion Condition=" '$(MajorVersion)' == '' ">3000</MajorVersion>
<MinorVersion Condition=" '$(MinorVersion)' == '' ">0</MinorVersion>
<PatchVersion Condition=" '$(PatchVersion)' == '' ">0</PatchVersion>

<BuildTimestamp>$([System.DateTime]::Now.DayOfYear.ToString().PadLeft(3,'0'))</BuildTimestamp>
Expand Down
59 changes: 54 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
# BigDecimal
BigDecimal is an arbitrary precision floating point number class.
BigDecimal is an arbitrary precision floating point number type/class.

It stores a **Mantissa** and an **Exponent**.
The Mantissa is of type BigInteger, enabling BigDecimal to have arbitrary precision.
BigDecimal is a base-10 floating point number, like System.Decimal is. This is unlike System.Double, which is a base-2 floating point number.

**NOTE: BREAKING CHANGE FOR VER. 3000.0.0:**
The default Precision value for the library has been changed from 5000 to 100. This should provide a much more reasonable default value for the vast majority of the users. 5000 digits of precision by default was a poor choice, is likely more precision than anyone needs, and resulted in performance issues after a couple of multiplications (assuming BigDecimal.AlwaysTruncate is false, which is the default).

Like other floating point number implementations, it stores a Mantissa and an Exponent.
The difference is, these values are of type BigInteger, and so can be arbitrary precision.
## QUICK START
Here is what you need to know:
You will want to configure BigDecimal to obtain the behavior that you want.
This is done via two static fields of BigDecimal:
- `BigDecimal.Precision`
- `BigDecimal.AlwaysTruncate`

You set them like this (these are the default values being set here, BTW):
```csharp
BigDecimal.Precision = 100;
BigDecimal.AlwaysTruncate = false;
```

### BigDecimal.Precision

This is the default precision that BigDecimal uses for all BigDecimal instances.
The value is specified in the number of digits to the right of the decimal place that you want.



The default value is `100`.




### BigDecimal.AlwaysTruncate




This value specifies whether or not BigDecimal will round the value of a BigDecimal to `BigDecimal.Precision` places after every arithmetic operation.



The default value is `false`.




Setting this setting to `true` keeps the values constrained to only `BigDecimal.Precision` digits. This limits the ammound of memory used and keeps the arithmetic performant.

However, the number has the potential to lose precision as you go, depending on how you use it.

The dynamics of if and when BigDecimals lose precision with this setting enabled isn't nessisarily complicated, but it does require some discussion.

[See the documentation](https://github.com/AdamWhiteHat/BigDecimal/wiki/Documentation#using-bigdecimal) for a more in depth discussion on this topic.

---


:new: Now supports logarithms and trigonometric functions:
Expand All @@ -30,7 +79,7 @@ LogN, Ln, Log2, Log10, Exp, Sin, Cos, Tan, Cot, Sec, Csc, Sinh, Cosh, Tanh, Coth



:cockroach: [View out open issues](https://github.com/AdamWhiteHat/BigDecimal/issues) if you are experiencing a bug or have an idea for a new feature. You can also discuss new feature ideas in the [discussion](https://github.com/AdamWhiteHat/BigDecimal/discussions) forums first. An 'issue' for the new feature can be created from a discussion at any time.
:cockroach: [View open issues](https://github.com/AdamWhiteHat/BigDecimal/issues) if you are experiencing a bug or have an idea for a new feature. You can also discuss new feature ideas in the [discussion](https://github.com/AdamWhiteHat/BigDecimal/discussions) forums first. An 'issue' for the new feature can be created from a discussion at any time.



Expand All @@ -43,7 +92,7 @@ Example usage:
```csharp
Console.WriteLine(BigDecimal.Precision);
// 5000
BigDecimal.Precision = 200; // Tone down the precision for this demo.
BigDecimal.Precision = 200; // Set the precision for this demo to 200 digits.
Console.WriteLine(BigDecimal.Precision);
// 200
Expand Down
5 changes: 1 addition & 4 deletions TestBigDecimal/TestBigDecimalCritical.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ public void TestAlwaysTruncate()
Assert.AreEqual(expected2, actual2, "#: 2");
Assert.AreEqual(expected3, actual3, "#: 3");
Assert.AreEqual(expected4, actual4, "#: 4");
Assert.AreEqual(5000, BigDecimal.Precision, "Restore Precision to 5000");
}

[Test]
Expand Down Expand Up @@ -446,9 +445,7 @@ public void TestTruncateOnAllArithmeticOperations()
Assert.AreEqual(expected8, actual8, $"Test Truncate On All Arithmetic Operations - #8: ");
Assert.AreEqual(expected9, actual9, $"Test Truncate On All Arithmetic Operations - #9: ");
Assert.AreEqual(expected10, actual10, $"Test Truncate On All Arithmetic Operations - #10: ");
Assert.AreEqual(expected11, actual11, $"Test Truncate On All Arithmetic Operations - #11: ");

Assert.AreEqual(5000, BigDecimal.Precision, "Restore Precision to 5000");
Assert.AreEqual(expected11, actual11, $"Test Truncate On All Arithmetic Operations - #11: ");
}
}

Expand Down

0 comments on commit ccc4193

Please sign in to comment.