Bug #13344 CAST(1E+300 TO signed int) on little endian CPU, wrong result
Submitted: 20 Sep 2005 9:55 Modified: 20 Oct 2005 18:20
Reporter: Matthias Leich Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:
Assigned to: Jim Winstead CPU Architecture:Any

[20 Sep 2005 9:55] Matthias Leich
Description:
Example:
   My box (Intel Pentium M - little endian)
        SELECT 1.0E+300, CAST(1.0E+300 AS   SIGNED INT);
        1.0E+300	CAST(1.0E+300 AS   SIGNED INT)
        1e+300	-9223372036854775808  <------ wrong

         BTW: INSERT INTO ... <SIGNED BIGINT> =  1.0E+300;
                  Produces a warning + shows the expected value
                  9223372036854775807
                  That means the problem seems to be within the 
                  function CAST.

    aix52 (Power PC -- big endian)
         SELECT 1.0E+300, CAST(1.0E+300 AS   SIGNED INT);
         1.0E+300        CAST(1.0E+300 AS   SIGNED INT)
         1e+300  9223372036854775807   <----- correct

The manual says in chapter 
   11.1.1. Overview of Numeric Types:
     BIGINT[(M)] [UNSIGNED] [ZEROFILL]

     A large integer. The signed range is -9223372036854775808 to
     9223372036854775807

   11.2. Numeric Types
     ...
    When asked to store a value in a numeric column that is outside
    the column type's allowable range, MySQL clips the value to the
    appropriate endpoint of the range and stores the resulting 
    value instead.

This behaviour on storage time is also applied to queries, CAST
whenever the maximum value range of a numeric data type is exceeded.

My environment:
   - Intel PC with Linux(SuSE 9.3)
   - MySQL compiled from source
        Version 4.1 ChangeSet@1.2417.1.2, 2005-09-11
        Version 5.0 ChangeSet@1.1980, 2005-09-19

aix52:
    - PowerPC
    - Version 5.0 last ChangeSet around 2005-09-13
I assume we have this inconsistent behaviour since the views
are available. 

This bug might be not so important for customers, but it
harms the development of testcases. Currently we can
only have one file with expected testresults for all
hardware architectures. 

How to repeat:
Please execute the statements above.
[20 Sep 2005 12:50] Matthias Leich
Please forget the
   I assume we have this inconsistent behaviour since the views
   are available.
It was a mistake during cut and paste.
[22 Sep 2005 22:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/30240
[13 Oct 2005 15:13] Jim Winstead
Fixed in 4.1.16 and 5.0.15.
[20 Oct 2005 18:20] Paul DuBois
Noted in 4.1.16, 5.0.15 changelogs.