5

I have some code which returns float::PositiveInfinity to indicate that an event will never happen but for some reason the compiler (MS Visual Studio 2013) gives me the following warning:

warning C4756: overflow in constant arithmetic

The code in question looks like this:

property float MinsRemainingUntilNextEvent
{
    virtual float get()
    { 
        return float::PositiveInfinity;
    }
}

What does that mean and should I care? MS's documentation didn't explain it for me...

Jon Cage
  • 36,366
  • 38
  • 137
  • 215

1 Answers1

6

I would bet that the implementors of the compiler chose to emit the warning for any floating-point expression that could be evaluated at compile-time and the result of which was +inf, meaning that the warning would systematically be emitted for float::PositiveInfinity.

Your use of float::PositiveInfinity is completely valid and harmless. Ignore the warning. I would like to recommend you get a better compiler but GCC is similarly silly when it comes to floating-point.

Community
  • 1
  • 1
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • 1
    Thanks; I changed my code to use float::MaxValue in the end as that will work in my instance and doesn't raise a warning. – Jon Cage Sep 05 '14 at 08:09