docs/en/sql-reference/functions/arithmetic-functions.md
Arithmetic functions work for any two operands of type UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, or Float64.
Before performing the operation, both operands are cast to the result type. The result type is determined as follows (unless specified differently in the function documentation below):
UInt8 + UInt16 = UInt32 or Float32 * Float32 = Float64.UInt32 + UInt128 = UInt128 or Float32 * Float64 = Float64.UInt32 * Int32 = Int64 or UInt32 * UInt32 = UInt64.These rules make sure that the result type will be the smallest type which can represent all possible results. While this introduces a risk of overflows around the value range boundary, it ensures that calculations are performed quickly using the maximum native integer width of 64 bit. This behavior also guarantees compatibility with many other databases which provide 64 bit integers (BIGINT) as the biggest integer type.
Example:
SELECT toTypeName(0), toTypeName(0 + 0), toTypeName(0 + 0 + 0), toTypeName(0 + 0 + 0 + 0)
┌─toTypeName(0)─┬─toTypeName(plus(0, 0))─┬─toTypeName(plus(plus(0, 0), 0))─┬─toTypeName(plus(plus(plus(0, 0), 0), 0))─┐
│ UInt8 │ UInt16 │ UInt32 │ UInt64 │
└───────────────┴────────────────────────┴─────────────────────────────────┴──────────────────────────────────────────┘
Overflows are produced the same way as in C++.
<!-- The inner content of the tags below are replaced at doc framework build time with docs generated from system.functions. Please do not modify or remove the tags. See: https://github.com/ClickHouse/clickhouse-docs/blob/main/contribute/autogenerated-documentation-from-source.md --> <!--AUTOGENERATED_START--> <!--AUTOGENERATED_END-->