Arbitrary Precision Struct in C# (BigDecimal)

I created an arbitrary precision struct (and called it BigDecimal) in C# using the built in BigInteger for handling the "mantissa" and a normal int for the "exponent".

Orriginally, I wanted to make a Unit Conversion Library soon realized that I will be handling very small and very large numbers, and converting between those numbers would yield even smaller or larger numbers so I started working on this "struct" and quickly forgot about the main project and focus on this only.

This is only one big file which you can drop in your project and use, plus it is well documented so hopefully you won't get lost.

All the important features are implemented like basic arithmetic operations and operator overloading and string parsing. But the toString method only has one option (to output the full number without rounding or chopping) and the Pow and Exp methods are not implemented because I couldn't figure out how to calculate them in this context.

Here is the source if you want to use it or give me advice on how to improve it.

by XXISerenaIXX via /r/csharp

Leave a Reply