
AMDG Deane Yang <deane_yang <at> yahoo.com> writes:
F(d, v) = [(d/d_0)^{1/3}/ (v/v_0)^{sqrt(2)} - (v/v_0)^(-5/4}] * F_0
where d_0 = 1 meter, v_0 = 1 meter/second, and F_0 = 1 newton.
Then if your library has implicit unit conversions, then formula will be properly calculated, no matter what units the input values d and v are in.
But surely I'm telling you anything new? I'm pretty sure I learned tricks like this from physicists. So I still need an example where this approach does not work or where the extra divisions cause a serious problem.
Deane
If d_0, v_0, and F_0 are units instead of quantities, everything will work perfectly and there will be no extra divisions at runtime when the quantity is already in the correct system. I can think of two cases where temorarily bypassing quantity can be useful. The first is when you already have a function that operates on the raw value_type. Then you can simply write an overload taking a quantity which forwards to that function. The second case is when the value_type is a complex UDT. In this case it may be possible to write the function in a much more efficent way by using it directly. Of course, the usual caveats about optimization apply. In Christ, Steven Watanabe