Bug #65295 COT() Function returns wrong result
Submitted: 12 May 2012 17:43 Modified: 13 May 2012 8:00
Reporter: Kimo Maru Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Data Types Severity:S2 (Serious)
Version:5.5 OS:Linux (Wrong results returned)
Assigned to: CPU Architecture:Any

[12 May 2012 17:43] Kimo Maru
Description:
When you add enter the following statements, the wrong result is returned;

How to repeat:
CREATE TABLE Test (TestID SMALLINT NOT NULL PRIMARY KEY, Amount SMALLINT NOT NULL);

My values;
INSERT INTO Test VALUES (101, 12), (102, 1), (103, 139), (104, -37), (105, 0), (106, -16);

My COT function statement;
SELECT TestID, Amount, COT(Amount) AS Cotangent FROM Test ORDER BY TestID;

When I execute, I get this error;
ERROR 1690 (22003): DOUBLE value is out of range in 'cot(`DVDRentals`.`Test`.`Amount`)' 

Suggested fix:
If I remove the (105,0) values, it works fine.  But, I believe it should work with them inserted and return a NULL value in the Amount field.
[13 May 2012 7:59] MySQL Verification Team
Marking as a duplicate.   I already filed this bug months ago, internally.
Bug 12878196 - COT (0) GIVES ERROR AND 1/TAN(0) GIVES NULL + WARNING ?

The devs wrote this:

It is not consistent with the SQL standard. Generally, the strategy used in
the standard is to raise an exception when there is an arithmetic error.

Besides, it means that users must be prepared for two error tests when
processing queries: 1) Check for exception, and 2) check for NULL value
and/or a warning. Having just the exception test is much simpler.
[5 Aug 2013 3:36] Roberto Spadim
why not continue with the documented standard?
cot(0) = null
maybe add a warning, but don't create a 'error'
or, change the documents
see this bug:
http://bugs.mysql.com/bug.php?id=69916

i didn't read the cot function code, but maybe a sql_mode could be used too... like the invalid_dates mode