BaH.muParser - fast math parser
BlitzMax Forums/Brucey's Modules/BaH.muParser - fast math parser
| ||
Something new for the weekend ;-) (well, I had a long weekend, so Monday counts!) BaH.muParser is an extensible high performance math parser library. The speed comes with the conversion of the expression into bytecode. You can define your own variables, constants, operators and functions. Currently available via the maxmods SVN repository. Still working on the documentation, and will be released proper once that's done. A small example of usage : SuperStrict Framework BaH.muParser Import BRL.StandardIO Try Local parser:TmuParser = New TmuParser Local fVal:Double = 1 Local expr:String = "MyFunc(a) * sin(a)" parser.DefineVar("a", fVal) parser.DefineFun1("MyFunc", MyFunction) parser.SetExpr(expr) Print parser.Eval() ' change the value of the variable and re-evaluate fVal = 15 Print parser.Eval() Catch e:TmuParserException Print e.message End Try Function MyFunction:Double(fVal:Double) Return fVal * 10 End Function ' ' Output : ' 0.17452406437283513 ' 38.822856765378113 Enjoy :o) |
| ||
How does this compare speed-wise to native BlitzMax math operations? Is there any speedup there, or is it 'just' intended to make math operations scriptable? |
| ||
Since this will be used with BlitzMax the various trigonometric functions should probably use degrees. |
| ||
Is there any speedup there, or is it 'just' intended to make math operations scriptable? No, it calls the same functions as BlitzMax does, and yes, it's just a parser. :-) ...trigonometric functions should probably use degrees. Good point. Done. |
| ||
Excellent! Now I can allow scripts to do mathematical equations without doing any kind of parsing on my end. Thanks again Brucey. |
| ||
Released. Please let me know if you have any problems with it. Thanks. |
| ||
It works. I ran the two examples with no problem. I'm a little surprised that ATan2 is not one of the built-in functions. Of course it can be added easily enough. |
| ||
How are constants used? Specifically string constants. |