Sphinx大数计算问题

时间:2014-02-25 10:42:23

标签: sphinx

我已将mysql客户端与sphinx服务器连接 当我发出此查询时

select 20130919.0+(15/4),15/4 from [INDEX] limit 1; 我得到以下结果

+------+--------+-------------------+----------+
| id   | weight | 20130919.0+(15/4) | 15/4     |
+------+--------+-------------------+----------+
| 7414 |      1 |   20130924.000000 | 3.750000 |
+------+--------+-------------------+----------+

请注意,15/4会返回3.75但是当它添加到20130919.0时会返回错误的结果。

在另一种情况下,当我写下面的查询

select 2222+15/4,15/4 from [INDEX] limit 1;

返回正确的结果。

+------+--------+-------------+----------+
| id   | weight | 2222+15/4   | 15/4     |
+------+--------+-------------+----------+
| 7414 |      1 | 2225.750000 | 3.750000 |
+------+--------+-------------+----------+

类似于前一种情况,第三列应具有值20130922.75。我认为问题是狮身人面像会使数字回合,但在这种情况下它应该是20130923.000而不是20130924.000

我想要的是它应该返回正确的浮点数,但它的行为很奇怪。希望这里有人对此行为有任何解释。

1 个答案:

答案 0 :(得分:2)

Sphinx主要进行单精度浮点数学

http://en.wikipedia.org/wiki/Single-precision_floating-point_format

仅使用8位作为指数。精确存储的十进制数字大约为7 - 你有8个。

有一个double()函数,但我没有测试过它。


编辑:实际上没有,双()不会有帮助。

sphinxQL>select double(20130919.0)+(15/4),15/4  from sample2 limit 1;
+---------------------------+----------+
| double(20130919.0)+(15/4) | 15/4     |
+---------------------------+----------+
|           20130924.000000 | 3.750000 |
+---------------------------+----------+
1 row in set (0.03 sec)

sphinxQL>select double(20130919.0+(15/4)),15/4  from sample2 limit 1;
+---------------------------+----------+
| double(20130919.0+(15/4)) | 15/4     |
+---------------------------+----------+
|           20130924.000000 | 3.750000 |
+---------------------------+----------+
1 row in set (0.02 sec)