I've looked around quite a bit for a fast math parser in either C or Objective-C Almost all of the libraries I saw are written in C++, and I don't really want to go through the hassle of getting that to compile. Can anyone make a recommendation?
Asked
Active
Viewed 5,663 times
8
-
3Try [TinyExpr](https://github.com/codeplea/tinyexpr). It's in a single C source code file and header. – 131 Jan 22 '16 at 21:20
-
Just want to second **TinyExpr**. Super easy to use. – rileyk Aug 25 '16 at 20:24
4 Answers
6
I haven’t used them myself, but you could try GCMathParser and DDMathParser.
-
3+1 for DDMathParser! hoorah! (Although if you're going for raw speed, it's nearly impossible to beat GCMathParser) – Dave DeLong Feb 03 '11 at 22:28
-
@Dave: I knew about Graham's parser, but I'd somehow missed yours. Fascinating structure with the use of blocks. It seems like the use of NSNumber, with frequent generation of autoreleased instances, might slow things down a bit. It looks like it might be possible to use simple floating point types for the calculations, which might be much faster. – Brad Larson Feb 03 '11 at 23:18
-
1@Brad yeah, there's a lot that could be done to optimize it; my goal was extension and readability, not necessarily efficiency. :) Also, it's using `NSDecimal` for calculations (so much more precision than a floating point type). – Dave DeLong Feb 03 '11 at 23:31
-
Although this is an extremely old post, may I ask if there is a math parser in that can deal with complex numbers? – DaPhil Nov 14 '13 at 11:55
5
There won't be any hassle with the compiling, ObjC can work side by side with any C++ class. Search for ObjC++ here, its really pretty easy (its basically just renaming everything from *.m to *.mm)

JustSid
- 25,168
- 7
- 79
- 97
0
There is a Code Project where this problem was addressed. Note this is for C++ -- sorry just saw that you're looking for C / Objective-C. As it builds a library, you could write a simple interface and expose it to C. There's a really succinct explanation here of how to go about doing this.

M. Tibbits
- 8,400
- 8
- 44
- 59