
AMDG Noah Roberts <roberts.noah <at> gmail.com> writes:
"Converting the second to match the first" doesn't make sense to me. I guess you might be talking about operands of '+'? Yeah, not necessary.
The answer is pretty simple. All arithmetic operators work in the base system. The result is converted on assignment if necessary.
Ok. What happens here: std::cout << (x + y) << std::endl; Is the unit printed a. the unit of x b. the unit of y c. the base unit
Both of these require storing twice as much information as the current implementation.
There is one condition in which that is necessary. That is if you are using a value that is entered by the user and the calculation loop keeps requesting it from whatever object it is provided by. Then, in order that the conversion isn't repeatedly done you would want to store two values...the user entered value and the converted value. The reason you wouldn't just store the converted value is double creep...the number might change on the user. I imagine that a developer who needs to can work with this so that it does not happen...so that the calculation loop is not asking for the same conversion on the same value repeatedly.
Any other time it is sufficient that you keep only the user entered value and the unit (ie the conversion factor) to translate it into the base system...OR...the converted value in the base system without a conversion factor.
The former is exactly what I said. It stores two doubles instead of one. Further, temp = a + b; c = temp * d; is not equivalent to c = d * (a + b); Every operation incurs an extra multiplication per operand. This is a far cry from zero overhead. The latter does not have any significant benefit over the current implementation. In Christ, Steven Watanabe