Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-09-14 10:22:12


> I too am curious how this would come up. I can think of function that
> would have a signature of:

> mass/volumn density(mass m, distance r)
>
> but why would you want two fuctions:
>
> kg/m^3 density(kg m, m r)
> kg/cm^3 density(kg m, cm r)

Sure, I can come up with an example. Suppose you want to know how much
energy is being delivered by a particle accelerator. You're a doctor
calculating a dose for a patient, so you want the energy either in ergs
or calories (I'm not really sure what doctors will use, but it's not
electron volts). On the other hand, the energy of the beam is typically
measured with two quantities: first, the energy of a given particle, in
some electron-volt scale, and the luminosity of the beam, in units
which can be converted to particles per second (luminosity is more
complicated than this, but let me finesse this for purposes of the
example). Your calculation will be something like:

        energy/particle * particles/second * seconds of exposure

but you will want to implicitly convert from MeV/second to ergs/second.

I'm sure this is not the only example. There must be many examples
where calculations need to cross domains in which the conventional
units are different.

Now, SIunits handles this, as best as can tell, transparently and
easily. That is IMHO how it should be. A programmer should not need to
worry about whether her internal representation is in inches or
centimeters or light-seconds, unless she is running up against
representable range issues, and then she will work hard to get it
right. SIunits allows you to do this with limited manual intervention
needed, by defining your own view, defining the conversion constants
once from the fundamental representation. This is IMHO how it should be.

> So I see the need for having IO from and into various units. But once
> inside C++, I'm not sure why you would mix units.

You need to have the ability to represent different units for
representable range issues, primarily. Representing cosmological
distances in femtometers or particle physics lengths in megaparsecs is
going to run into trouble, especially when you cube lengths to get
volumes.

Once you have the ability to represent measurements in different views,
you naturally are going to have potential incompatibilities between
different libraries which make different natural choices of those
views, so supplying the conversions becomes important.

George


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