Maximum value a variable can hold without documentation
The first step should be

count = 0
while (x*2 &gt; x)
  x = x*2
  count++


to find the largest power of 2 that can fit into the variable. Note that doing +1 instead of *2 is not only much slower but also fails for floating point numbers (the gaps between large consecutive floating point numbers are bigger than 1). The above procedure should work for both numbers that roll over and numbers that reach infinity.

Once you have a rough estimate, you may perform a binary search in the range from estimate, to 2*estimate to find an exact bound.