From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-05-09 16:10:50
> I don't think that mixed operations with floating point values should give a
> floating point result.
> If the class has absent/explicit constructors from fp types, this will
> prevent many usual expressions;
> and if it has regular constructors from fp-types it will produce too many
> temporaries and conversions.
"When in doubt, do as the ints do," and int * double is a double.
If not that, what else? If you return a decimal, you're throwing away
double precision information. I don't think that doing that by default
is right. If you don't need the precision, you should explicitly throw
it away yourself, or never have used the double as the other piece in
the first place (create a decimal constant in place if it is an
efficiency issue, for example).
I don't think you're thinking about the temporaries/conversions the
same way I am; remember that it's not just the ones that will seem to
be in user code that are important. The internal logic of
operator*(decimal,double) will (unless you emulate a FP operator
internally) have to go through a double result. If you want to return a
decimal type, the internal logic would have to convert back; and then
if I *do* want a double, you're saying I have too many temporaries and
conversions? No, let the internal logic return the logical datatype,
which incidentally is the better one for efficiency.
The only place in C++ where the compiler throws precision away
gratuitously is the implicit conversion of double to int, and IMHO that
one is a design flaw. I don't think we want another.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk