1

Similar to this question but different. Lots of good answers there, but none do Units of Measure.

How about a .NET compatible (even through COM, if necessary) mathematical expression evaluator which incorporates units of measure?

I've tried NCalc for unitless expressions. I know F# can do it in code. Google Calculator is amazing but unavailable as a supported API and is inappropriate in its service-basis for this project.

Here's an interesting paper on the subject. It covers Units of Measure calculations but leaves out "additive constant" conversions such as Celsius to Fahrenheit (by their conclusion). And it brings up a good point about substance. "Gallons of gasoline" vs "gallons of milk". The units are the same, but the substance is different and so perhaps should be treated as different by the library. And with the right alchemist equations, how much milk with a gallon of gasoline yield? :-P

Is NCalc hookable to achieve this? How much work would be involved in enhancing NCalc otherwise? Are there any other .Net compatible libraries that can handle Units of Measure?

Community
  • 1
  • 1
Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
  • 1
    You could evaluate F# expressions at runtime. – CodesInChaos Dec 06 '11 at 22:37
  • F# is great, it's just not appropriate for this situation unless it could accept googleCalc-like syntax, not include advanced non-expression evaluation functionality, allow for custom symbol/variable binding, and provide helpful/easy errors to guide the user toward a valid expression. Can you provide a full answer that acts like google calculator? – Jason Kleban Dec 07 '11 at 01:00

1 Answers1

0

FParsec seems interesting! It only helps with the expression parsing steps, but that seems like most of the battle. Supports compact, BNF-like definitions in F# and can provide high-quality error messages.

Dimensional Anaylsis is still a custom job, but with a properly parsed AST, would it be hard to implement?

Jason Kleban
  • 20,024
  • 18
  • 75
  • 125