Boost logo

Boost :

From: Jan Langer (jan_at_[hidden])
Date: 2003-10-16 13:13:01

Deane Yang wrote:
>> The library has to make some choice about the internal way it
>> represents the exponents, and the users just have to follow whatever
>> convention the library has.
>> The concern is if a user stuffs dimensions into the n-tuple that do
>> not have the same semantics the library expects (e.g. multiplication
>> of two numbers does not result in the exponents in their n-tuples
>> being added). If the library is hard coded to do conversion as if the
>> n-tuple contained physical dimensions, the library may incorrectly
>> compute types for arithmetic expressions.
> I'm sorry if I confused people. I never meant to say that the user
> should be able to specify the semantics of the exponents. I only meant
> that the user should be able to define the fundamental dimensions/units
> to be used (so, not necessarily mass, length, and time). As far as I
> know, you always want to add the exponents when you multiply two
> quantities. I even think that this is a mathematical fact and therefore
> should be hardwired (just as 2+2 = 4 is hardwired).

if everyone would agree on that it would make many things easier. but
what about the gasoline example:
        you have two types of gasoline and you cant mix (add) them
        basically they represent the same physical unit (volume)

two things can be done:
1 - they can either be just used as one unit
2 - two different units for each of them

i think 2 is the right way and any conversion must be allowed explicitly
by the user like:

typedef list_c <int, 1, 0>::type gasA;
typedef list_c <int, 0, 1>::type gasB;

// m^3 as base quantity
quantity <double, gasA> const gallon_gasA (0.00378);
quantity <double, gasB> const gallon_gasB (0.00378);
quantity <double, gasA>
tank = 2 * gallon_gasA + 3 * gallon_gasB; // error

quantity <double, gasA>
tank = mix_gas (2 * gallon_gasA, 3 * gallon_gasB); // sometimes error

> But I do think it worthwhile to allow rational exponents (but NOT
> arbitrary precision). I'd like someone to show me a real example
> where the exponent had a numerator or denominator other than 1, 2, 3, or
> 4. (Even 4 is, for me, a stretch)

do you mean to prohibit denominators above 4? what is the problem with a
compile time rational number library (like david richardson posted) and
whoever needs a unit system can provide his own type for the exponents.
(at least if it is addable and subtractable)


jan langer ... jan_at_[hidden]
"pi ist genau drei"

Boost list run by bdawes at, gregod at, cpdaniel at, john at