MySQL查找双精度的最小值/最大值 [英] MySQL Finding min/max values for double

查看:152
本文介绍了MySQL查找双精度的最小值/最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关的MySQL文档指出:对于双打:


允许的值是-1.7976931348623157E + 308至-2.22507385850720142014E-308、0和2.2250738585072014E-308至1.7976931348623157E +308。

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


这些是基于IEEE标准的理论限制。实际范围可能会略小,具体取决于您的硬件或操作系统。

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

我发现系统上的实际范围实际上较小!是否有SQL查询或其他方法可以找出双精度的实际最小值和最大值是什么?

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

执行一个简单的循环以1开头的值并将其插入。在每个循环中,将值乘以10,直到溢出失败。最后,您将获得minWorkingValue和maxFailedValue。

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.

现在执行第二个循环,在minWorkingValue和maxFailedValue之间插入一个值。如果成功,它将成为新的minWorkingValue。如果失败,它将成为新的maxFailedValue。继续直到maxFailedValue-minWorkingValue =1。最后,minWorkingValue是您可以插入的实际最大值。

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.

或者,如果您非常确定知道这些值的位置,可能是,然后跳过第一步,手动设置minWorkingValue和maxFailedValue并直接进入第二个循环。

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.

这篇关于MySQL查找双精度的最小值/最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆