Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2003-10-03 10:55:21


Hi, I am a Newbie to Boost :-)

I am currently working on an upgrade to a
point-and-click small wind turbine rotor blade design app,
which involves various physics.
The original did its math in terms of inbuilt types ,
 but significant time is spent looking up (say)
whether a length is in metres or millimetres
 or an angle in degrees or radians.
I have also had requests from users for ability to work
 in (say) feet and inches etc rather than s.i. units.

I have had a look at various physical quantities libraries
 including the "quantities" library at boost,
and SIunits at
http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/SIunits/doc/0SIunits.html

 but they have an odd syntax.

ie both do something like:

        length mylength = 20 * metres(); // here length is a type

whereas what would seem to be more useful would be:

        metres myLength(20); // here metres is the type
                                        //*1 see footnote on explicit ctor

The critical difference here is that the type is the
 unit of dimension, rather than the dimension itself.
As a programmer if I want to know the units
of a variable they are encoded in the type
 and if I can't decipher them I can do a conversion:

metres mylength = metres(length_with_unknown_units);
// ok... whatever units length_with_unknown_units was ,
// mylength is its value in metres.

I have spent some time creating a physical_quantities class template,
 with this approach, and have put the source code and
  a demo programme (and sample output) on my web site at:
http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

I would be interested to hear any views
 as to whether this approach is worth pursuing, or suggestions or
improvements.
( Alternatively there may be a library that does this that I havent found
... ? )

note: I have tried to answer some obvious questions and criticisms
 in the Potential FAQ on the page.

---
*1 / this example is actually an error if  coded as:
metres myLength =1;
 in my version of physical_quantities
  because it violates dimensional analysis.

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