From: Andy Little (andy_at_[hidden])
Date: 2004-01-09 01:13:16
"Reece Dunn" <msclrhd_at_[hidden]> wrote in message
> Andy Little wrote:
> >Documentation and link to a download, for my lib can be found here. :
> Cool. I'll look into the library.
> As far as I can see, there are several areas that a quantities library
> deal with. The basic concepts are:
[ some definitions ]
Some of the terms above may be similar to mine:
> Prefixes -- A set of powers that express the size magnitude of the value
> a base unit (e.g. micro; milli; tera; giga for base 10 and bit; byte;
> tebi for binary). NOTE: these could (and should) be expressed within a
> constants framework.
I represent these in my type (variable) by a number(template param),
which represents the power of 10, in the SI system.
The technique could be applied in hex or binary too.
m --> 0 0 = log10(1)
km --> 3 3 = log10(1000)
mm --> -3 -3 = log10(.001)
The advantage of this is that a lot of maths can be performed at compile
10 mm * 10 km -> 100 m2 // ie 100 square meters
In this example the only Runtime multiplication is 10 * 10.
The return type of the calculation is in metres.
The value of the unit of the return type is arrived at
by adding the logs of the units at compile time:
Using the values of the powers from the above example:
3 + -3 = 0
This approach is quite powerful, where a sequential calculation is
a = b * (c / d) * e;
note: the units of 'a' may not have the same units as the temporary r-value,
but where the units differ only 1 scaling is required for the entire calc.
This has been found to increase both speed and accuracy of calculations
In a templated function a temporary may be required which does not require
using the metaprogramming paradigm with the example above:
template <typename A, typename B, typename C, typename D, typename E>
return_type func ()
typedef typename pq_divide< C, D>::type div_cd;
typedef typename pq_multiply<B,div_cd>:: type mux_b_cd;
typename pq_multiply<mux_b_cd, E>::type a
= ( b * (c / d) ) * e; // brackets help clarity
Here only the internal values are used in calculation and init of a.
There is no runtime scaling at all.
[ examples ]
> The units system should allow something like:
> si::speed s = 7 * si::m / si::s;
> si::acceleration g = 9.2 * si::m / si::s_2; // si::s_2 = si::s * si::s
I have Severe Problems with the above syntax.
In my syntax I would declare a vector of accelerations in m.s-2 like this:
The type above is compile-time complete and can therefore be used as a
There may be an equivalent declaration method using your syntax,
but I would like someone to show me how the above declaration should be
done, using it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk