Portable math support for Decimal that Microsoft forgot and more.
The .NET Decimal data type is included in .NET, but is often overlooked for scientific calculations. It's high precision and exact up to 28 decimal places and it's available in any .NET environment.
You might be in a situation where you just need a lot more precision than Double can provide. I used Decimal for calculating locations in space for CNC manufacturing and pick and place control. I've found the increased precision of Decimal reduces overall errors throughout the set of calculations and it also improves the odds of reversing the calculations if necessary for debugging. In that case it ends up being a kind of oversampling.
Unfortunately, a lot of the usual number functionality is not provided for .NET. For example, you can't calculate a square root or even perform exponentiation. You can cast to Double for these operations, but you can end up with a significant loss of precision.
Note All of this I've used in the "real world", but this is also a hobby. Although the library is performant, I've perferred accuracy and readability to raw performance.
Install via NuGet package manager console:
PM> Install-Package DecimalMath.DecimalEx
Or of course you can clone the repository and pull in the projects directly.
This project contains two portable libraries.
Bridges the gap in .NET support.
Sqrt
Pow
Exp
Log
Sin
, Cos
, Tan
ASin
, ACos
, ATan
, ATan2
Floor
/ Ceiling
to a given number of decimal placesGCF
, AGMean
, and a fault-tolerant Average
Provides support for high-accuracy geometric calculations. Note: This is still a work in progress. It's been used in production, but it still needs some more grooming (was originally VB code) and unit tests.
Point
, Line
, and Vector
Circle
and Arc
This project uses the MIT License. See the license file in the same folder as this readme.