12,753,809 members (31,568 online)
alternative version

#### Stats

112.7K views
48 bookmarked
Posted 29 Jul 2005

# Math Parser

, 25 Aug 2005 CPOL
 Rate this:
Solve mathematical equations

## Introduction

This is a parser which uses RegEx to solve mathematical expressions.

## How To Use It?

```MathParser.Parser p = new MathParser.Parser();
if( p.Evaluate( "-(5-10)^(-1)(3+2(cos(3Pi)+(2+ln(exp(1)))^3))" ) )
Console.WriteLine( p.Result );
else Console.WriteLine( "Error." );```

## Features

• Functions
• `abs`
• `acos`
• `asin`
• `atan`
• `cos`
• `cosh`
• `floor`
• `ln`
• `log`
• `sign`
• `sin`
• `sinh`
• `sqrt`
• `tan`
• `tanh`
• Operators: +, -, *, , ^, !
• Constants: `Pi`

```p.Mode = MathParser.Mode.RAD;
p.Mode = MathParser.Mode.DEG;

Or:

`Parser p = new Parser( MathParser.Mode.DEG );`

`2(1+3(1e3+1)) = 2*(1+3*(1000+1)) = 2*(1+3(1000+1)) = 2(1+3*(10^3+1)) = 6008`

`2(1+4(5Pi+2,2e3)(5+2)^3)` is the same as `2*(1+4*(5*Pi+2200)*(5+2)^3)`.

## Known Problems

I tested this parser on a German operating system (WinXP).
If I want to convert a `string `to `double `(e.g. "`3.123`") the decimal point must be a "`,`" (`Convert.ToDouble("3.123"`) would throw an Exception).
I'm not sure if this works on an English version of WinXP.

If there are any problems with the decimal point, just report it and I will fix it.

## Bug Fixes

• Fixed some problems with exponents

## Share

 Germany
No Biography provided

## You may also be interested in...

 Ignoring comma when called by SQL Assembly Leo Kruz25-Nov-09 3:59 Leo Kruz 25-Nov-09 3:59
 The Parser does not respect presedence her´minator4-Mar-09 21:20 her´minator 4-Mar-09 21:20
 (exp(2)) not working TominatorBelgium3-Mar-09 7:59 TominatorBelgium 3-Mar-09 7:59
 cos(8) bey0nd8512-Jan-09 0:08 bey0nd85 12-Jan-09 0:08
 10*20+5*10 - No Result ? Victor Vanchesa15-Nov-07 12:42 Victor Vanchesa 15-Nov-07 12:42
 Problem with expression Avrin174-Oct-07 1:12 Avrin17 4-Oct-07 1:12
 Re: Problem with expression Member 773069617-Aug-11 17:24 Member 7730696 17-Aug-11 17:24
 ln(exp(1)) evaluating correctly for you? BreakableC21-Sep-07 2:13 BreakableC 21-Sep-07 2:13
 Last Visit: 31-Dec-99 19:00     Last Update: 22-Feb-17 3:38 Refresh « Prev12345 Next »