[Exceptional C++ Style] Item 30: double or Nothing

Adrian Fagg adrianf at evaluategroup.com
Mon Feb 14 06:43:12 EST 2005


> -----Original Message-----

> I'm currently working with floating point a fair bit, and I
> know I know just
> enough to know it is difficult. I looked at the example,
> knowing it had to
> be a trap and having a hunch that it would not complete, but I still
> couldn't see why until I read it. Then it was obvious of
> course (short float
> typically has only 7 digits of precision), but it just goes
> to show how easy
> it is to miss these problems when you are not on guard for them.

I have two rules:
Don't use floating point numbers unless you know you can get away with it.
Never use float unless you are desperate for space *and* know you can get
away with it.
This latter rule has meant that I've never used the float type in my career
so far and I can't imagine that I ever will now.

These rules mostly keep me out of trouble.

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/




More information about the Effective-cpp mailing list