Dec 5, 2011 at 10:19 PM
Edited Dec 6, 2011 at 3:29 PM
I have an application wherein users might deal with dollars ('$'), percentages ('%'), Gigabytes('GB'), and plain old counts. Formulas need to be able to track the units of measure through to the final answer. Can it be done with NCalc?
Google calculator knows how to preserve the units of measure through a calculation, but I don't know how it does it.
I imagine that Terms must be of like units (or Types?) and that there is some precedence of units of measure. Here's a quick list off the top of my head, but perhaps there's a more basic way to think of it.
x + x : x, $ + $ : $, % + % : %, % + 2 => % + 200% : %, GB + GB : GB, GB + MB : GB, x + ? : ERR
x * x : x, x * ? : ?, $ * % : $, % * % : %, $ * $ : ERR, $ * GB : ERR, $ / GB : ($/GB)
The syntax is [unit operation unit : result unit]. ERR doesn't have to fail the computation completely, just the unit preservation part.
As I write that short list, I realize that there's a lot of challenging problems represented in just these examples. Normalizing to giga, mega, kilo. Asymmetry of * and /.
I did some research, clearly starting from zero. I posted this general question on stackoverflow with some findings: http://stackoverflow.com/questions/8403098