Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-08-30 19:02:33


> On Thursday 30 August 2001 20:33, Ken Shaw wrote:
>
> > As I'm sure the guys at JPL thought when different groups mixed radians and
> > seconds of arc in the guidance software for the Mars Climate Orbiter.
>
> Do you have any evidence about JPL using some sort of quantity library?
> I suspect they used bare doubles or whatever they are called in Ada.
> This *is* the sort of thing a quantity library should prevent.

In fact, a library such as the vaporware one I'm thinking of would help
dramatically here. Strictly speaking, both radians and seconds of arc
are dimensionless quantities, so a dimensionality library alone doesn't
help. But there is a conversion between them, a scale factor. Thus if
one of the variables was:

unit<angular,radians_system>

and the other

unit<angular,arc_seconds_system>

the code linking the two groups' code would either have done the
correct (we hope) implicit conversion, or would have failed to compile.

(Yeah, I'm probably simplifying the template syntax that would be
required, but probably most of it can get hidden behind typedefs and
some clever use of namespaces to help out.)

> > I think it should restrict the user to one set of measures or the other
> > with no mixing or conversion possible. Allowing both in the same
> > calculation will insert conversion errors because of the inherent
> > dissimularities of the 2 systems.
>
> As long as the conversion is explicit (and is called
> dangerous_inexact_unit_conversion<pounds_force>(kilogram) :) there's no
> problem.

Why not just

unit<mass, kilogram_system> kg = 1;
unit<mass, pounds_mass_system> pounds = kg;

In pounds_mass_system the mass weighing 1 pound at the surface of the
earth has a mass of 1. There's no reason you can't use those units, and
it would probably be quite natural for, say, a produce wholesaler in
the US. It's not even that dangerous; it's a mass and can't be
converted implicitly into a force, you still have to supply an
appropriately unit-ed acceleration.

> If you don't provide a conversion, then there *is* a problem, because the
> user will provide one for himself -- incorrectly.

This I agree is the biggest danger. Especially since typos and thinkos
will happen in doing these conversions; I don't think I can count the
number of times I've multiplied when I should have divided, or
converted a number twice...

George Heintzelman
georgeh_at_[hidden]


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