Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2007-03-28 13:38:47


> How do you implement conversions between units that require more
> complicated arithmetic expressions (e.g. units of temperature)?
> Conversions for the vast majority of units are simply multiples of
> each
> other and the conversion can be expressed at compile-time and
> multiplied by a runtime quantity value:

Take a look at unit_example_20 to see a demonstration of implementing
temperature conversions (both absolute and relative). It turns out
that relative temperature conversions are trivial (converting a
temperature difference of 32 degrees Fahrenheit to Kelvin just
involves the scale factor of 5/9). Absolute temperatures are the
issue. Basically, at this point the library assumes that all
quantities are relative as that makes the default behavior the most
sensible. While it is probably worthwhile to have the absolute<>
concept (also could be point<>) as a part of boost::numeric, I don't
think it is really something that properly belongs in the unit
library itself; hence it is only an example... You can achieve
basically arbitrary conversions between quantities by specializing
the conversion_helper<quantity1,quantity2> class...

Matthias


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