|
change the mode to DEG, then you will get the right results.
|
|
|
|
|
Hi.
I'm using the DLL MathParser like a SQL Server assembly.
But, in this case, when i pass something like (1,1) + (2,0) calling via sql assembly, the comma is ignored, so the result is 11+2!
I'm using a dll made in C# with this method (it uses the MathParser DLL like reference in the project):
public static double RetornaValorCalculado(string nom_formula)
{
try
{
MathParser.Parser p = new MathParser.Parser();
if (p.Evaluate(nom_formula))
return Convert.ToDouble(p.Result);
else
return (0);
}
catch (Exception)
{
return (0);
}
}
Att.,
Leonardo.
|
|
|
|
|
it will fail to calculate 3+4*7 correctly!
|
|
|
|
|
Hi,
When i enter the formula "(exp(2)+2)*3", the parser fails. It makes the formula "(*exp(2)+2)+3", with the leading *, as you can see. That creates a parsing error further on.
The regex is so complex i can't understand it at all :-/
Otherwise nice tool so far!
Cheers
|
|
|
|
|
cos(8)= 8
cos8= -0,145500033808614
all Funktions like cos/sin/sqrt with parenthesis don't work
|
|
|
|
|
I tried 10*20+5*10 and there is no Result.
Do I need to put () on it ?
|
|
|
|
|
Hi all,
1/ A simple way to add binary and hexadecimal support:....(see below)
2/ A bug with acos following cos (or asin following sin ...)
1/ Code to add hex/bin support (0xsomething and 0bsomething)
<br />
Regex regEx = new Regex("0[xX][A-Fa-f0-9]+", RegexOptions.IgnoreCase);<br />
Match h = regEx.Match(Expression);<br />
while (h.Success)<br />
{<br />
Expression = Expression.Replace(h.Value, Convert.ToInt32(h.Value.Substring(2), 16).ToString());<br />
h = regEx.Match(Expression);<br />
}<br />
<br />
regEx = new Regex("0[bB][0-1]+", RegexOptions.IgnoreCase);<br />
h = regEx.Match(Expression);<br />
while (h.Success)<br />
{<br />
Expression = Expression.Replace(h.Value, Convert.ToInt32(h.Value.Substring(2), 2).ToString());<br />
h = regEx.Match(Expression);<br />
}<br />
2/ acos bug
If you've got an expression like
cos(0.1) + acos(0.2)
Regexp that replace first cos will also replace second one and expression become
0.9950041653 + a0.99500416530.2
Best regards
pierre
|
|
|
|
|
How to call function for hex and bin in winforms app calculator??
Thanks in advance.
|
|
|
|
|
(1073102848-182349824)/1073102848)*100
this does not return a result for me
Please help?
|
|
|
|
|
|
The ln(exp(1)) seems to evaluate incorrectly for me. I'm no way a Regexp guru, so please could address this one?
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
There is a bug in MathParser. For modes other than RAD, functions ACOS, ASIN, and ATAN don't work properly.
E.g. you calculate ASIN as: a=asin(factor*b), where you use "factor" to convert angle to radians. Unfortunately with ASIN the angle is not the "input" but rather the "output", so you should rather do a=asin(b)/factor. Same goes for acos and atan
|
|
|
|
|
I would like to use "MathieuMathParser" DLL via C#.net 2005.
But I can't add it to refrences.
erorr:
please make sure that the file is acceseble and that is a valid assembly or COM component.
Have anyone ever uesed it via C#??
|
|
|
|
|
Hi Paratrooper!
I've a big problem with the math parser.
Something about my environment:
PC 1
- Intel Celeron (32 Bit only)
- Windows XP Pro. with SP2 Deutsch/German, 32 Bit Version
- MS .NET Framework 2.0
PC 2
- Virtual Machine on PC 1 using VMware Workstation 5.5.2
- Ubuntu Linux, 32 Bit Version
- Mono Project 1.1.13.8 .NET Runtime
PC 3
- Intel Pentium D 950 CPU (32 Bit, with 64 Bit Extensions)
- Windows XP Pro. with SP2 Deutsch/German, 32 Bit Version
- MS .NET Framework 2.0
PC 4
- AMD Opteron (32 Bit, with 64 Bit Extensions)
- SuSE Linux 10, 64 Bit Version
- Mono Project 1.1.13.8 .NET Runtime
Problem:
I use the math parser as a simple calculator (console application).
When I try to evaluate the expression "(4264 * 0,052) + 800" on PC1 & PC2 the
result is "1021.728" (correct). The same program returns on PC3 & PC4 the value "222528.0"!
Other Samples:
0,5 * 10 = 5 (On PC1 & PC2)
0,5 * 10 = 50 (On PC3 & PC4)
I don't understand these "strange" results.
I've tried to solve the problem but I don't know much about RegEx.
Remark: I've tried to compile the program on all pc's above. Makes no difference
Thanks, Daniel
|
|
|
|
|
Daniel,
I am having a similar problem:
The sample you gave:
0,5 * 10 = 50 (On PC3 & PC4)
Returns 50 for me too.
Regards,
Luc Pettett
|
|
|
|
|
You got this Problem cause all Win64 Bit Edition are English. In the German Language Pak are only some Ressources translated - not the internal .Net String-Formating-Routines. So it's the described Problem with the decimal Point.
Xynratron
|
|
|
|
|
I Got Error when i tried the 10/(3+(4*5)/12*48+17) expression
Whats Wrong?
Thanks
|
|
|
|
|
I solved your expression. The result was 0.1 (no error).
|
|
|
|
|
Para manejar cualquier funcion:
string ecuacion="cos(X-asin(2,3*X))+exp(X)-ln(cos(X*sin(X+2)))"; //la funcion que quieras!
Ejem: Reemplazar X por 2,0001
Evaluar(2,0001);//el resultado final! =)
public double Evaluar(double value)
{
string temporal = ecuacion;
MathParser.Parser p = new MathParser.Parser();
while (ecuacion.IndexOf("(") > 0)
{
int inicio = ecuacion.LastIndexOf("(") + 1;
int fin = ecuacion.IndexOf(")", inicio);
string temp = ecuacion.Substring(inicio, fin - inicio);
try
{
double resultado = Double.Parse(temp);
string temp1 = ecuacion.Substring(inicio - 1, fin - inicio + 2);
ecuacion = ecuacion.Replace(temp1, resultado.ToString());
}
catch
{
p.Evaluate(temp.Replace("X", Convert.ToString(value)));
ecuacion = ecuacion.Replace(temp, p.Result.ToString());
}
}
p.Evaluate(ecuacion.Replace("X", Convert.ToString(value)));
ecuacion = temporal;
return p.Result;
}
|
|
|
|
|
Hi, would it be possible to add support for logical operators (<,>, == etc.), whose result instead of true or false would be 1 or 0 respectivelly?
Felin
|
|
|
|
|
Hello there,
i tried some floating point expressions and it seems the floting value is mistreated, as its integer part is being removed in most operations. This is what i cannot fix as my regex skills are weak.
Some test cases:
0.00004730/2 becomes 00004730/2
4.73004469661202E-05/2 becomes 73004469661202E-05/2
1114.73004469661202E-05/2 becomes 73004469661202E-05/2
1114.730+2 becomes 730+2
I would be glad to see this fixed, because this nice Solver fits into my app very good.
Tnx in advance!
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
Hello,
I wrote this parser on a german operating system.
It searches for double values like "1,53E-2" or "123,56" etc.
Values like "4.7534" will be ignored.
Replace the code below and the parser should work on your non-german system.
// Solve Sin, Cos, Tan...
Regex regEx = new Regex( @"([a-z]{2,})([\+-]?\d+\.*\d*[eE][\+-]*\d+|[\+-]?\d+\.*\d*)", RegexOptions.IgnoreCase );
// Solve Factorial.
...
regEx = new Regex( @"(\d+\.*\d*[eE][\+-]?\d+|\d+\.*\d*)!" ); // Search for patterns like 5!
// Solve power.
regEx = new Regex( @"\{(.+)\}\^(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" ); // Search for patterns like {-5}^-1
regEx = new Regex( @"(\d+\.*\d*e[\+-]?\d+|\d+\.*\d*)\^(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" ); // Search for patterns like 5^-1
// Solve multiplication / division.
regEx = new Regex( @"([\+-]?\d+\.*\d*[eE][\+-]?\d+|[\-\+]?\d+\.*\d*)([\/\*])(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" );
// Solve addition / subtraction.
regEx = new Regex( @"([\+-]?\d+\.*\d*[eE][\+-]?\d+|[\+-]?\d+\.*\d*)([\+-])(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" );
Servus...
Paratrooper.
|
|
|
|
|
Hello Paratrooper,
Tnx for the solution - it works great. Strangelly i thought i had problems with "," as decimal separator, but now it seems I didn.
I actually changed the code to be like:
@"([a-z]{2,})([\+-]?\d+" + RegxNumericSeparator + @"*\d*[eE][\+-]*\d+|[\+-]?\d+,*\d*)"
where the RegxNumericSeparator is a escapeSpecialChars(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
The escapeSpecialChars is not very nice, and because of this I wont post it (regex are not my friends yet), but i believe everybody knows what it does.
Breakable
============
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
Hey Paratrooper666,
Nice code. The fix works fine except for one thing:
When you enter a decimal number without the zero, e.g. (.4 instead of 0.4)
the parser returns an incorrect result.
Any suggestions on how to fix it???
Thanks,
Louis
|
|
|
|
|
Its not that the integer part is being removed its a problem with the sequencing of the operations within the Solve function.
For example take 0.00004730 * 2.0. This is quite rightly calculated as 0.000946. However, this is is replaced into the expression as 9.46E-4.0 The problem comes is that the "Solve addition / subtraction" code picks up on the minus sign and tries to calculate
(9.46E) - (4.0) this causes an error.
Otherwise, it's a pretty good piece of code and potentially extremely useful. Boolean evaluations like those suggested would be useful.
Cheers
Simon
A great programmer merely hasn't been asked to do the impossible yet!
|
|
|
|