From 43521e50c9811b74e3a4fe29e2e0ce181a34c96e Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Fri, 13 May 2022 10:18:41 -0700 Subject: [PATCH] Specify optional Exponential Histogram Aggregation, add example code in the data model (#2252) --- specification/metrics/data-model.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/specification/metrics/data-model.md b/specification/metrics/data-model.md index fd5399aa156..90bf4424e0b 100644 --- a/specification/metrics/data-model.md +++ b/specification/metrics/data-model.md @@ -791,6 +791,21 @@ func MapToIndexScale0(value float64) int { } ``` +Implementations are permitted to round subnormal values up to the +smallest normal value, which may permit the use of a built-in function: + +```golang + +func GetExponent(value float64) int { + // Note: Frexp() rounds submnormal values to the smallest normal + // value and returns an exponent corresponding to fractions in the + // range [0.5, 1), whereas we want [1, 2), so subtract 1 from the + // exponent. + _, exp := math.Frexp(value) + return exp - 1 +} +``` + ##### Negative Scale: Extract and Shift the Exponent For negative scales, the index of a value equals the normalized