Float¶
Floating-point data types are used to store numbers with fractional components. Tinybird supports Float32, Float64, and BFloat16 for different precision requirements.
For calculations requiring high precision, especially with financial or business data, consider using the Decimal type instead. Floating-point numbers can introduce rounding errors and may not always provide exact results.
Equivalent types:
Float32:float.Float64:double.
Float types have the following aliases:
Float32:FLOAT,REAL,SINGLE.Float64:DOUBLE,DOUBLE PRECISION.
Using floating-point numbers¶
- Computations with floating-point numbers might produce a rounding error.
SELECT 1 - 0.9
Result:
┌───────minus(1, 0.9)─┐ │ 0.09999999999999998 │ └─────────────────────┘
- The result of the calculation depends on the calculation method (the processor type and architecture of the computer system).
- Floating-point calculations might result in numbers such as infinity (
Inf) and “not-a-number” (NaN). This should be taken into account when processing the results of calculations. - When parsing floating-point numbers from text, the result might not be the nearest machine-representable number.
NaN and Inf¶
Tinybird supports special floating-point values that represent infinity and undefined results.
Inf: Represents positive infinity.
SELECT 0.5 / 0
Result:
┌─divide(0.5, 0)─┐ │ inf │ └────────────────┘
-Inf: Represents negative infinity.
SELECT -0.5 / 0
Result:
┌─divide(-0.5, 0)─┐ │ -inf │ └─────────────────┘
NaN: Represents "Not a Number," indicating an undefined or unrepresentable result.
SELECT 0 / 0
Result:
┌─divide(0, 0)─┐ │ nan │ └──────────────┘
See the rules for NaN sorting in the section ORDER BY clause.
BFloat16¶
BFloat16 is a 16-bit floating-point data type characterized by an 8-bit exponent, a sign bit, and a 7-bit mantissa.
This type is particularly useful for machine learning and AI applications where reduced precision can offer performance benefits.
Tinybird supports conversions between Float32 and BFloat16. Most other operations are not directly supported for BFloat16.