DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(mysql.info.gz) Arithmetic functions

Info Catalog (mysql.info.gz) Numeric Functions (mysql.info.gz) Numeric Functions (mysql.info.gz) Mathematical functions
 
 12.4.1 Arithmetic Operators
 ---------------------------
 
 The usual arithmetic operators are available. Note that in the case of
 `-', `+', and `*', the result is calculated with `BIGINT' (64-bit)
 precision if both arguments are integers.  If one of the argument is an
 unsigned integer, and the other argument is also an integer, the result
 will be an unsigned integer.   Cast Functions.
 
 `+'
      Addition:
 
           mysql> SELECT 3+5;
                   -> 8
 
 `-'
      Subtraction:
 
           mysql> SELECT 3-5;
                   -> -2
 
 `-'
      Unary minus. Changes the sign of the argument.
 
           mysql> SELECT - 2;
                   -> -2
 
      Note that if this operator is used with a `BIGINT', the return
      value is a `BIGINT'!  This means that you should avoid using `-'
      on integers that may have the value of `-2^63'!
 
 `*'
      Multiplication:
 
           mysql> SELECT 3*5;
                   -> 15
           mysql> SELECT 18014398509481984*18014398509481984.0;
                   -> 324518553658426726783156020576256.0
           mysql> SELECT 18014398509481984*18014398509481984;
                   -> 0
 
      The result of the last expression is incorrect because the result
      of the integer multiplication exceeds the 64-bit range of `BIGINT'
      calculations.
 
 `/'
      Division:
 
           mysql> SELECT 3/5;
                   -> 0.60
 
      Division by zero produces a `NULL' result:
 
           mysql> SELECT 102/(1-1);
                   -> NULL
 
      A division will be calculated with `BIGINT' arithmetic only if
      performed in a context where its result is converted to an integer!
 
 `DIV'
      Integer division.  Similar to `FLOOR()' but safe with `BIGINT'
      values.
 
           mysql> SELECT 5 DIV 2;
                   -> 2
 
      `DIV' is new in MySQL 4.1.0.
 
 
Info Catalog (mysql.info.gz) Numeric Functions (mysql.info.gz) Numeric Functions (mysql.info.gz) Mathematical functions
automatically generated byinfo2html