def compare_as_floats(xs, ys, error):
def f(x):
try:
y = float(x)
if not math.isfinite(y):
log.warning('not an real number found: %f', y)
return y
except ValueError:
return x
xs = list(map(f, xs.split()))
ys = list(map(f, ys.split()))
if len(xs) != len(ys):
return False
for x, y in zip(xs, ys):
if isinstance(x, float) and isinstance(y, float):
if not math.isclose(x, y, rel_tol=error, abs_tol=error):
return False
else:
if x != y:
return False
return True
评论列表
文章目录