
Boost : 
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 20070216 18:15:53
On 2/16/07, Matthias Schabel <boost_at_[hidden]> wrote:
> > if (aircraft.altitude > ground_elevation + min_agl_offset)
> >
> > as
> >
> > if (unit_cast<elevation_type>(aircraft.altitude) > ground_elevation +
> > min_agl_offset)
>
> This is actually a very good example of the problem; here there are
> two steps,
> the addition operation and the comparison. Without specifying a priori a
> particular common base unit system through which all conversions are
> mediated (which is basically the same as requiring everyone use one unit
> system), this is just fundamentally ambiguous  it has nothing to do
> with
> implementation. If I ask :
>
> Is 3 feet plus 1 meter less than one fathom?
>
> How would you answer it? Naturally, you would want to convert to some
> common unit of length, but which one? There are three choices, and all
> are roughly equivalent. Now, in this case, it doesn't matter since
> all three
> systems would give you the same answer, but since there is no good way
> for the compiler to make this decision automatically,the reasonable
> thing
> for it to do is issue an error. this problem doesn't go away if you have
> runtime units either  it is just fundamentally bad practice to have the
> compiler make arbitrary decisions in arithmetic expressions.
I see. I find this area interesting, although I am hoping you stick
to compiletime only for now.
I think the only hard part is the arithmetic portion. A comparison
only deals with two types, and it doesn't matter which way (precision
aside, maybe there could be some smarts here) the conversion happens,
the result is the same.
3 feet + 1 meter, what is the result? What are the pros/cons to
always using the lefthandside type? If a decision was made,
arithmetic would be defined, and comparisons would be easy.
I realize this should not be a focus of the current library, and
again, I'm not asking for it. I do not know what the ramifications in
terms of implementation and usage are. It just interested me.
Michael Fawcett
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk