quantileBFloat16
Computes an approximate quantile of a sample consisting of bfloat16 numbers. bfloat16
is a floating-point data type with 1 sign bit, 8 exponent bits and 7 fraction bits.
The function converts input values to 32-bit floats and takes the most significant 16 bits. Then it calculates bfloat16
quantile value and converts the result to a 64-bit float by appending zero bits.
The function is a fast quantile estimator with a relative error no more than 0.390625%.
Syntax
quantileBFloat16[(level)](expr)
Alias: medianBFloat16
Arguments
Parameters
level
β Level of quantile. Optional. Possible values are in the range from 0 to 1. Default value: 0.5. Float.
Returned value
- Approximate quantile of the specified level.
Type: Float64.
Example
Input table has an integer and a float columns:
ββaββ¬βββββbββ
β 1 β 1.001 β
β 2 β 1.002 β
β 3 β 1.003 β
β 4 β 1.004 β
βββββ΄ββββββββ
Query to calculate 0.75-quantile (third quartile):
SELECT quantileBFloat16(0.75)(a), quantileBFloat16(0.75)(b) FROM example_table;
Result:
ββquantileBFloat16(0.75)(a)ββ¬βquantileBFloat16(0.75)(b)ββ
β 3 β 1 β
βββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ
Note that all floating point values in the example are truncated to 1.0 when converting to bfloat16
.
quantileBFloat16Weighted
Like quantileBFloat16
but takes into account the weight of each sequence member.
See Also