Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get warning C4756: overflow in constant arithmetic when returning float::PositiveInfinity?

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...

like image 712
Jon Cage Avatar asked Sep 04 '14 13:09

Jon Cage


1 Answers

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.

like image 121
Pascal Cuoq Avatar answered Nov 01 '22 08:11

Pascal Cuoq