Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2008-01-04 09:01:38


Neil Groves wrote:
> Are you certain that mixing floating-point types and integral types is
> desirable?
>
> floating-point types are, of course, approximations unlike integer
> types. It
> is dangerous to mix the two, and the approach to do so should not be
> allowed
> even by a policy. Mixing floating point types with integer types
> implicitly
> is a poor software engineering practice without merit in my humble
> opinion.
>
> Implicit type conversion has been a frequently regretted design
> decision in
> my experience despite the initial syntactic appeal.

What do you consider is wrong with using integer literals to represent
constants, where those constants are indeed integers?

Either in code such as:

my_real -= 1;

or in tables of (integer) coefficients to polynomials?

In this case my_real is a template type, so the conversion may or may not
loose precision depending upon the type, but the since result is always
represented as the floating point type, then there is no more accurate way
to represent an integer than as an... integer.

Converting the other way most certainly is wrong, of course.

All IMHO,

Regards, John.


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