Class: OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::ExponentMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb

Overview

LogarithmMapping for mapping when scale < 0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scale) ⇒ ExponentMapping

Returns a new instance of ExponentMapping.



16
17
18
19
20
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb', line 16

def initialize(scale)
  @scale = scale
  @min_normal_lower_boundary_index = calculate_min_normal_lower_boundary_index(scale)
  @max_normal_lower_boundary_index = IEEE754::MAX_NORMAL_EXPONENT >> -@scale
end

Instance Attribute Details

#scaleObject (readonly)

Returns the value of attribute scale.



14
15
16
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb', line 14

def scale
  @scale
end

Instance Method Details

#calculate_min_normal_lower_boundary_index(scale) ⇒ Object



30
31
32
33
34
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb', line 30

def calculate_min_normal_lower_boundary_index(scale)
  inds = IEEE754::MIN_NORMAL_EXPONENT >> -scale
  inds -= 1 if -scale < 2
  inds
end

#get_lower_boundary(inds) ⇒ Object

for testing

Raises:

  • (StandardError)


37
38
39
40
41
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb', line 37

def get_lower_boundary(inds)
  raise StandardError, 'mapping underflow' if inds < @min_normal_lower_boundary_index || inds > @max_normal_lower_boundary_index

  Math.ldexp(1, inds << -@scale)
end

#map_to_index(value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb', line 22

def map_to_index(value)
  return @min_normal_lower_boundary_index if value < IEEE754::MIN_NORMAL_VALUE

  exponent = IEEE754.get_ieee_754_exponent(value)
  correction = (IEEE754.get_ieee_754_mantissa(value) - 1) >> IEEE754::MANTISSA_WIDTH
  (exponent + correction) >> -@scale
end