NEW
|
import math |
× |
2 |
|
|
NEW
|
INF = float("inf") |
× |
NEW
|
MINUS_INF = float("-inf") |
× |
NEW
|
NaN = float("NaN") |
× |
6 |
|
|
7 |
|
|
NEW
|
def floatToGoString(d): |
× |
NEW
|
d = float(d)
|
× |
NEW
|
if d == INF:
|
× |
NEW
|
return '+Inf' |
× |
NEW
|
elif d == MINUS_INF:
|
× |
NEW
|
return '-Inf' |
× |
NEW
|
elif math.isnan(d):
|
× |
NEW
|
return 'NaN' |
× |
16 |
else:
|
|
NEW
|
s = repr(d)
|
× |
NEW
|
dot = s.find('.')
|
× |
19 |
# Go switches to exponents sooner than Python.
|
|
20 |
# We only need to care about positive values for le/quantile.
|
|
NEW
|
if d > 0 and dot > 6: |
× |
NEW
|
mantissa = f'{s[0]}.{s[1:dot]}{s[dot + 1:]}'.rstrip('0.') |
× |
NEW
|
return f'{mantissa}e+0{dot - 1}' |
× |
NEW
|
return s
|
× |