|
Boost : |
From: Deane Yang (deane_yang_at_[hidden])
Date: 2004-01-13 13:46:39
Phil Richards wrote:
> Ok, I'll bite. Some questions about practical usage.
I'll bite, too. These are good questions.
>
> What is the result of
> torque(1.0) / work(1.0)
> ? I assume it has dimensionality "torque^1,work^-1". Or does it have no
> dimensionality?
In the dimensions library I want, the user would be able to decide which
behavior would occur.
>
> If you've got work, I assume you've also got time, mass, length as either
> base dimensions or derived dimensions. What is the dimensionality of
> 0.5 * mass(1.0) * power<2>(length(3.0) / time(4.0))
> ? torque^1? work^1? Neither?
>
Let's make this even simpler.
Suppose you multiply
force(1.0) * length(1.0)
Is the result torque or work? (Of course, if we were doing
multidimensional dimensional analysis and distinguished between
a dot product and a cross product, we wouldn't have this difficulty!)
Here's my answer to my own question (and not Phil's!):
If I am writing a code module that uses only torque and not work,
then I would do the following:
a) inside the implementation, define only the dimensions force and
length and allow torque to be measured using the dimension force * length.
b) If I want to pass torque through the module interface in units
other than the natural one implied by the fundamental dimensions, then
I define the dimension "torque", which is used by the interface only
and is immediately converted into force * length by the implementation.
If I am writing a code module that uses both torque and work, then I
need to examine the logic and decide whether the same force and lengths
are being used to compute torque and work. Depending on what I see,
I would design the dimensions accordingly to distinguish between the two
and allow the computations I need and ban other ones.
And what if I am a physicist who needs to do calculations involving
mass, length, time, force, torque, and work all involving the same
inputs? Ah, I think I would use one of the physical quantities libraries
submitted so far and not even try to use custom types to distinguish
between torque and work. It just sounds too hard to me. I have never
denied the usefulness of SIunits or any of the other physical quantities
libraries, if one is indeed doing calculations involving more than two
physical dimensions.
A glance at Andy Little's web site convinced me that he has indeed
developed a library very well suited to his needs.
(By the way, my other reaction to the ambiguity of "force * length"
is that the usefulness of overloaded operators is probably overrated.
Each operator* probably should be replaced by a function with a more
informative name. For example, in the world of finance, there are
two different types of multiplication, multiplication by a discount
factor and multiplication by a probabiliy. I find it quite useful to
distinguish between the two by using two different functions, even
though 99% of the time the two functions do exactly the same thing.
Otherwise, the remaining 1% is a real killer. It has the added benefit
of making the code easier to understand.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk