CodePlexProject Hosting for Open Source Software

An arbitrary-precision decimal number library developed in C#.

This is a BSD licensed library for use by CLR/DLR languages (like VB.NET, C#, and F#) when developers would like to include arbitrary-precision arithmetic in their applications.

The library contains an abstract BigNum class (representing a generic immutable unbound number instance) and a concrete implementation (BigNumDec: an implementation using an internal base 10 representation and schoolbook algorithms). The BigNumDec implementation does not provide true rational number support as it does not internally represent numbers as a numerator/denominator pair (this is planned for a future release), it is more accurately described as a floating-point class.

The library also includes an Expression class which can parse and evaluate expressions with support for algebraic symbols (defined in a Dictionary<String,BigNum> instance). There exists no support for functions in expressions (this is also coming in a future release).

The library is small but untidy and could do with a good clean-up. I question my original design descision to have a base abstract class and to implement additional operations in the BigNum classes rather than in a dedicated "BigMath" static class.

You are encouraged to submit patches and improvements. This project is not under 24/7 active development.

The name "Sine" is taken from a university problem I wrote this library to solve in early 2008: to find the sine of 10^40 radians.

- Arbitrary-precision decimal arithmetic
- Expression evaluator class
- Relatively easy to use

using W3b.Sine; public class ExpressionSample { public static void Main(String[] args) { Dictionary<String,BigNum> symbols = new Dictionary<String,BigNum>() { {"x", 100} // the implicit conversion defined }; Expression expression = new Expression("1 + 2 / 3 * x"); BigNum result = expression.Evaluate( symbols ); Console.WriteLine( expression.ExpressionString + " == " + result.ToString() ); BigNum x = 100; BigNum xPow100 = x.Pow( 100 ); Console.WriteLine("100^100 == " + xPow100.ToString() ); } }

Last edited Oct 2, 2009 at 9:33 PM by W3bbo, version 13