Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/prometheus_client/utils.py: 28%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1import math 

2 

3INF = float("inf") 

4MINUS_INF = float("-inf") 

5NaN = float("NaN") 

6 

7 

8def floatToGoString(d): 

9 d = float(d) 

10 if d == INF: 

11 return '+Inf' 

12 elif d == MINUS_INF: 

13 return '-Inf' 

14 elif math.isnan(d): 

15 return 'NaN' 

16 else: 

17 s = repr(d) 

18 dot = s.find('.') 

19 # Go switches to exponents sooner than Python. 

20 # We only need to care about positive values for le/quantile. 

21 if d > 0 and dot > 6: 

22 mantissa = f'{s[0]}.{s[1:dot]}{s[dot + 1:]}'.rstrip('0.') 

23 return f'{mantissa}e+0{dot - 1}' 

24 return s