13,001,686 members (69,443 online)
Add your own
alternative version

#### Stats

114.9K views
4.4K downloads
47 bookmarked
Posted 29 Jul 2005

# Math Parser

, 25 Aug 2005
 Rate this:
Please Sign up or sign in to vote.
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

Choose between RAD, DEG and GRAD.

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

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

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Germany
No Biography provided

## Comments and Discussions

 First Prev Next
 known bug Member 113264231-Dec-15 20:48 Member 11326423 1-Dec-15 20:48
 How to add % error_5057-Sep-13 23:27 error_505 7-Sep-13 23:27
 ++ | +- | -- | -+ can occur mirtes_992-Jun-13 4:03 mirtes_99 2-Jun-13 4:03
 Claro y sencillo Member 42650077-Sep-12 11:20 Member 4265007 7-Sep-12 11:20
 Solution General, thanks for it! Member 773069628-Sep-11 14:13 Member 7730696 28-Sep-11 14:13
 Re: Problem with expression Member 77306968-Sep-11 17:36 Member 7730696 8-Sep-11 17:36
 My vote of 1 sepehr101417-Jul-11 5:05 sepehr1014 17-Jul-11 5:05
 Multiplying by 0.6 Member 427553922-Jul-10 12:22 Member 4275539 22-Jul-10 12:22
 2*8,7-(24,8+1500*0,8*0,00004-0,04*25-2*LOG(150*25)) fdepijper@ziggo.nl8-Jul-10 19:27 fdepijper@ziggo.nl 8-Jul-10 19:27
 Re: 2*8,7-(24,8+1500*0,8*0,00004-0,04*25-2*LOG(150*25)) BiedermannS14-Mar-13 21:26 BiedermannS 14-Mar-13 21:26
 Ignoring comma when called by SQL Assembly Leo Kruz25-Nov-09 2:59 Leo Kruz 25-Nov-09 2:59
 The Parser does not respect presedence her´minator4-Mar-09 20:20 her´minator 4-Mar-09 20:20
 (exp(2)) not working TominatorBelgium3-Mar-09 6:59 TominatorBelgium 3-Mar-09 6:59
 cos(8) bey0nd8511-Jan-09 23:08 bey0nd85 11-Jan-09 23:08
 10*20+5*10 - No Result ? Victor Vanchesa15-Nov-07 11:42 Victor Vanchesa 15-Nov-07 11:42
 gift:binary/hexadecimal and a bug... METRAWARE5-Nov-07 6:45 METRAWARE 5-Nov-07 6:45
 Re: gift:binary/hexadecimal and a bug... error_50528-Aug-13 3:25 error_505 28-Aug-13 3:25
 Problem with expression Avrin174-Oct-07 0:12 Avrin17 4-Oct-07 0:12
 Re: Problem with expression Member 773069617-Aug-11 16:24 Member 7730696 17-Aug-11 16:24
 ln(exp(1)) evaluating correctly for you? BreakableC21-Sep-07 1:13 BreakableC 21-Sep-07 1:13
 ACOS, ASIN , ATAN error roksy30-Aug-07 22:53 roksy 30-Aug-07 22:53
 MathieuMathParser add to refrence list. jad_jabi1-Aug-07 1:10 jad_jabi 1-Aug-07 1:10
 Problem with EMT64/AMD64 Extensions? DocEvil796-Nov-06 7:51 DocEvil79 6-Nov-06 7:51
 Re: Problem with EMT64/AMD64 Extensions? fdafdafdsa16-Nov-06 15:37 fdafdafdsa 16-Nov-06 15:37
 Re: Problem with EMT64/AMD64 Extensions? Xynratron15-Mar-07 2:53 Xynratron 15-Mar-07 2:53
 Error In Program sis138212-Sep-06 8:41 sis1382 12-Sep-06 8:41
 Re: Error In Program Paratrooper66612-Sep-06 11:55 Paratrooper666 12-Sep-06 11:55
 Re: Error In Program Member 77306965-Oct-11 12:36 Member 7730696 5-Oct-11 12:36
 Logical operators support Felin4-Aug-06 5:56 Felin 4-Aug-06 5:56
 More problems with floating point BreakableC16-May-06 4:08 BreakableC 16-May-06 4:08
 Re: More problems with floating point Paratrooper66618-May-06 11:23 Paratrooper666 18-May-06 11:23
 Re: More problems with floating point BreakableC18-May-06 23:05 BreakableC 18-May-06 23:05
 Re: More problems with floating point Lmello7-Jun-06 16:09 Lmello 7-Jun-06 16:09
 Re: More problems with floating point schubb4-Sep-06 6:54 schubb 4-Sep-06 6:54
 Re: More problems with floating point schubb4-Sep-06 7:26 schubb 4-Sep-06 7:26
 Re: More problems with floating point Paratrooper6664-Sep-06 11:21 Paratrooper666 4-Sep-06 11:21
 Re: More problems with floating point schubb4-Sep-06 22:31 schubb 4-Sep-06 22:31
 Re: More problems with floating point Paratrooper6665-Sep-06 10:26 Paratrooper666 5-Sep-06 10:26
 how to use the dll? ewighell28-Apr-06 21:56 ewighell 28-Apr-06 21:56
 Re: how to use the dll? Paratrooper66630-Apr-06 11:59 Paratrooper666 30-Apr-06 11:59
 Use CultureInfo.InvariantCulture. wout de zeeuw25-Aug-05 8:41 wout de zeeuw 25-Aug-05 8:41
 Error stenflo24-Aug-05 20:41 stenflo 24-Aug-05 20:41
 Re: Error Paratrooper66625-Aug-05 9:10 Paratrooper666 25-Aug-05 9:10
 Last Visit: 31-Dec-99 18:00     Last Update: 26-Jun-17 6:28 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 25 Aug 2005
Article Copyright 2005 by Paratrooper666
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid