开发者

MySQL Finding min/max values for double

The relevant MySQL documentation states that for doubles:

Permissible values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308.

and

These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system.

I'm finding that the actual range is actually smaller on my system! Is there a SQL query or some other way to find out what the actual minimum and maximum valu开发者_StackOverflowes are for a double?


If you want to find and prove you know the exact max value on a system, here is a way to do it in a few minutes of execution time.

Do a simple loop that starts with the value of 1 and inserts it. On each loop multiple the value by 10 until it fails on overflow. At the end of this you have the minWorkingValue and the maxFailedValue.

Now do a second loop that inserts a value halfway between minWorkingValue and maxFailedValue. If it succeeds it becomes the new minWorkingValue. If it fails it becomes the new maxFailedValue. Continue until maxFailedValue - minWorkingValue = 1. At the end minWorkingValue is your actual max value you can insert.

As an alternative, if you are pretty sure you know where these values might be, then skip the first step and manually set minWorkingValue and maxFailedValue and straight to the 2nd loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜