Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-06-22 17:38:52


Msk_at_[hidden] wrote:
>
> Would there be any interest in a small domain library for
> boost that handles dimensions (e.g. length, mass, power)
> and units (e.g. meters, feet, furlongs) of physical
> quantities?

> I would appreciate feedback on three main questions:
>
> 1) Is this appropriate for boost?

        IMHO, yes.

> 2) Has this already been done?

        Yes.

> 3) Does anyone see any fatal flaws in the general approach,

        It looks good to me.

        Some operations seems to be missing.
Suppose I write:

        pow(x,y)

and x,y have units. What is the result?
A more pragmatic example is Pythagoras:

        sqrt(x * x + y * y)

Here, x is in metres, so the argument to sqrt is
square metres, and the result should be in metres.
More generally, root(n,x) yields division
of the dimension by n (and an error if it isn't
integral -- unless you want to support fractal dimensions :-).
pow(x,n) yields multiplication of the unit by n.
So log(n,x) also yields division. (Guess?)

When it comes to trig functions ...
I guess I'm saying: dimensional correctness is a problematic
thing in physics, because all sorts of approximations
and kludges and special functions are used. At some stage,
you need to 'cast away' dimensions, do a pure computation,
then add the dimensions back.

        sin ( undim(x) ) metres()
        
It would be kind of nice to wrap this up in a single
'cast away/cast back' operation (but I can't see how).
[A way to wrap existing 'pure' functions with dimensions?]

Is there a cast away function?

-- 
John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk