Boost logo

Boost :

From: Ross MacGregor (ross__macgregor_at_[hidden])
Date: 2003-10-23 17:59:13


Ross MacGregor wrote:
> For example if you want your basic unit of length to be 299,792,458
> meters and you wanted your calculations to use floats. You may want to
> specify it like this:
>
> si_unit<float, 2.99792458e+8, meter_t> light_meters;
> si_unit<long double, 1.0, meter_t> meters;

Let me expand upon these thoughts.

Ok lets say we create a template called quantity:

template<typename T, typename Transform, typename Dimention>
class Quantity;

Quantity<float, one, meter_t> meters;
Quantity<float, scale(1000), meter_t> kilometers;
Quantity<float, scale(1.4959855e11), meters_t) AU;
Quantity<float, scale(0.000001), meters_t) micrometers;
Quantity<float, scale(9.4605e15), meters_t) lightyear;

Quantity<float, scale(0.3048), meter_t> feet;
Quantity<float, scale(1609.344), meter_t> miles;

1) All units are represented as SI units by convention.
2) Each quantity has its own precision. Use longs, floats, double, or a
custom type.
3) Each quantity uses a predefined dimention.
4) Each type provides a transformation to the base dimention (units).
5) Provides automatic type conversion of same dimention types.
6) Provides loss of precision warnings.

Is such an entity possible?

Would it make everyone happy?

Can a dimentional analysis library can be build on top of this? This
only addresses conversion/precision of units (miles <-> kilometers) it
does not address dimensional math (meters_per_second = meters / seconds).

-- 
Ross MacGregor

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