views:

128

answers:

0

I have a warning in my C++ code, regarding the use of FLT_MAX. The code is (very simply):

const float a_lot = FLT_MAX;

The generated warning is:

warning C4756: overflow in constant arithmetic

And it doesn't help if I change the code to:

const float a_lot = std::numeric_limits<float>::max();

I'm using Microsoft Visual Studio 2008 service pack 1 (and the accompanying C++ compiler, which makes it version "15.00.30729.01".) The compiler does NOT generate this warning in debug mode though, only in release builds.

As far as I can see, the relevant compiler switches I use are "/fp:fast" in all build configurations and "arch:SSE2" only in release builds.

Now, my question is why does this happen (would it be due to the not-completely-conforming implementation of IEEE-754 floats in SSE2?) and how can I fix this warning? Would it have any real effect on my code (or it's just nagging?) Even if the compiler is nagging without cause, I'd hate to just disable the warning (I like clean code!)

Thanks for any help, tip, insight, etc.