MCPcopy Index your code
hub / github.com/prometheus/client_python / floatToGoString

Function floatToGoString

prometheus_client/utils.py:9–25  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

7
8
9def floatToGoString(d):
10 d = float(d)
11 if d == INF:
12 return '+Inf'
13 elif d == MINUS_INF:
14 return '-Inf'
15 elif math.isnan(d):
16 return 'NaN'
17 else:
18 s = repr(d)
19 dot = s.find('.')
20 # Go switches to exponents sooner than Python.
21 # We only need to care about positive values for le/quantile.
22 if d > 0 and dot > 6:
23 mantissa = f'{s[0]}.{s[1:dot]}{s[dot + 1:]}'.rstrip('0.')
24 return f'{mantissa}e+0{dot - 1}'
25 return s
26
27
28def parse_version(version_str: str) -> tuple[Union[int, str], ...]:

Callers 7

_accumulate_metricsMethod · 0.85
sample_lineFunction · 0.85
_metric_initMethod · 0.85
_child_samplesMethod · 0.85
_compose_exemplar_stringFunction · 0.85
generate_latestFunction · 0.85
_isUncanonicalNumberFunction · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected