This code compiles without error:
#include <limits>
int main()
{
static_assert(std::numeric_limits<float>::infinity() == std::numeric_limits<float>::infinity() + 1.0f, "error");
static_assert(std::numeric_limits<double>::infinity() == std::numeric_limits<double>::infinity() + 1.0, "error");
return 0;
}
online version
You don't need to even use infinity. If the number is big enough, rounding errors become big enough so adding one to the number doesn't change it at all.
E.g.
static_assert(100000000000000000000000.f == 100000000000000000000000.f + 1.0, "error");
The specific number of 0
you have to put here may be implementation defined, though.
Always keep rounding in mind when you write programs that use floating point numbers.