ACOS()函数返回NULL

时间:2016-12-07 11:55:33

标签: mysql

我有点困惑。这是我的问题

mysql> select acos(cos( radians(37.09024) ) * cos( radians(37.09024) ) * cos(radians(-95.712891) - radians(-95.712891)) + sin(radians(37.09024)) * sin(radians(37.09024)));
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| acos(cos( radians(37.09024) ) * cos( radians(37.09024) ) * cos(radians(-95.712891) - radians(-95.712891)) + sin(radians(37.09024)) * sin(radians(37.09024))) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                         NULL |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select cos( radians(37.09024) ) * cos( radians(37.09024) ) * cos(radians(-95.712891) - radians(-95.712891)) + sin(radians(37.09024)) * sin(radians(37.09024));
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| cos( radians(37.09024) ) * cos( radians(37.09024) ) * cos(radians(-95.712891) - radians(-95.712891)) + sin(radians(37.09024)) * sin(radians(37.09024)) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                      1 |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

我知道ACOS功能的范围是[-1,1]。所以ACOS(1)必须为0。

mysql> select acos(1);                                                                                                       +---------+
| acos(1) |
+---------+
|       0 |
+---------+
1 row in set (0.00 sec)

mysql>

我的MySQL版本已经过时了,但我无法更新。 MySQL Ver 14.12 Distrib 5.0.22

我做了一个改变

select acos(cos( radians(37.09024) ) * cos( radians(37.09024) ) * cos(radians(-95.712891) - radians(-95.712891)) + sin(radians(37.09024)) * sin(radians(37.09024))<strong>*1</strong>);

并且工作了。但我没有理解为什么ACOS(...... ** 1 )能够奏效。当我做ACOS( 1 * ...)时,我没有工作。如果是这种情况,则返回不是数字。两种情况都应该起作用

1 个答案:

答案 0 :(得分:0)

版本4.0.17中报告了

Bug #2338 Trignometric arithmatic problems,但我无法在5.0.22版本中重现该错误。

测试:

Sub copy_lignes()

Dim DerLigA As Long
Dim DerLigB As Long
Dim i As Integer
Dim j As Integer
i = 2
j = 2
DerLigA = Sheets("sheet3").Range("A" & Rows.Count).End(xlUp).Row
DerLigB = Sheets("sheet3").Range("B" & Rows.Count).End(xlUp).Row
For i To DerLigA
    For j To DerLigB
        If Sheets("sheet3").Range("A" & i) = Sheets("sheet3").Range("B" & j) Then

            Sheets("sheet3").Range("A" & i).Copy Destination:=Sheets("sheet3").Range("E" & i)
            Sheets("sheet3").Range("B" & i).Copy Destination:=Sheets("sheet3").Range("F" & i)
            Sheets("sheet3").Range("C" & i).Copy Destination:=Sheets("sheet3").Range("G" & i)
            Sheets("sheet3").Range("D" & i).Copy Destination:=Sheets("sheet3").Range("H" & i)

        End If
    Next j
Next i
End Sub