|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-05-09 16:36:12
----- Original Message -----
From: George A. Heintzelman <georgeh_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, May 09, 2001 6:10 PM
Subject: Re: [boost] Fixed-Point Decimal Type
>
> > 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.
>
A fixed-point decimal number is not an integer number.
> If not that, what else? If you return a decimal, you're throwing away
> double precision information.
We don't know that.
What if the user is using fixed<18>. That's more precision than a double.
What about operations against a float number?
> 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).
>
You are assuming that a native fp type will have more precision than a given
fixed instance, but that's a false
assumption.
> 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.
>
Internal temporaries are a matter of implementation, and we are yet to know
what that would be.
We are discussing the interface here, we can't impose temporaties because of
an implementation detail.
Making a binary operation return other than the class type will always
involve a temporary.
Even if you were right and the operation would internally work with a
double, what about operations
against float and long double types?
> The only place in C++ where the compiler throws precision away
> gratuitously is the implicit conversion of double to int,
>
No. Precision is lost whenever you convert to a narrower type
(double->float, for instance).
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk