• Alexey Kopytov's avatar
    Backport of the patch for bug #8457 "Precision math: DIV · 7e3b4d21
    Alexey Kopytov authored
    returns incorrect result with large decimal value" 
     
    For the DIV operator, neither operands nor result were checked 
    for integer overflows. 
     
    This patch changes the DIV behavior for non-integer operands as 
    follows: if either of the operands has a non-integer type, 
    convert both operands to the DECIMAL type, then calculate the 
    division using DECIMAL arithmetics. Convert the resulting 
    DECIMAL value into BIGINT [UNSIGNED] if it fits into the 
    corresponding range, or throw an 'out of range' error 
    otherwise. 
    
    mysql-test/r/func_math.result:
      Added a test case for bug #8457.
      Fixed results for a test case depending on the wrong behavior.
    mysql-test/r/type_varchar.result:
      Fixed results for a test case depending on the wrong behavior.
    mysql-test/t/func_math.test:
      Added a test case for bug #8457.
    sql/item_func.cc:
      If either of the operands has a non-integer type, convert both 
      operands to the DECIMAL type, then calculate the division using 
      DECIMAL arithmetics. Convert the resulting DECIMAL value into 
      BIGINT [UNSIGNED] if it fits into the corresponding range, or 
      throw an 'out of range' error otherwise.
    7e3b4d21
func_math.test 10.4 KB