Hi Guys
Does anyone know of any classes that process string mathmatical equations ? E.g. 2+2(6*5(2-1)) - It is specified on the command line and stored as a string.
Hi Guys
Does anyone know of any classes that process string mathmatical equations ? E.g. 2+2(6*5(2-1)) - It is specified on the command line and stored as a string.
: parsing command-line strings like 2+2(6*5(2-1)) requires more than the standard math functions; you either write a small parser or reuse a library. is right that writing your own is a viable learning path, and 's math-library pointer is useful for numeric functions but does not parse infix strings by itself.
A practical way to implement your own parser is the shunting-yard approach (infix -> RPN -> evaluate). Key steps to get right:
2( or )( or 2x -> 2*().If you prefer a ready-made solution, consider:
Troubleshooting tips: add unit tests for tricky cases (implicit multiplication, nested functions, unary minus, large nesting depth). Decide on semantics for ambiguous input (is 2(3) allowed?), choose a numeric type (double vs long double), and watch locale decimal separators. For production, prefer a battle-tested library for performance and robustness; write your own only if you need custom behavior or as an exercise.
Jump to Post— WaltP 2,905Only the ones you write.
Only the ones you write.
there is a math library.
Here's a link:
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.