MCPcopy Create free account
hub / github.com/ActiveState/code / ratio

Function ratio

recipes/Python/578138_gprof2dotpy/recipe-578138.py:63–77  ·  view source on GitHub ↗
(numerator, denominator)

Source from the content-addressed store, hash-verified

61tol = 2 ** -23
62
63def ratio(numerator, denominator):
64 try:
65 ratio = float(numerator)/float(denominator)
66 except ZeroDivisionError:
67 # 0/0 is undefined, but 1.0 yields more useful results
68 return 1.0
69 if ratio < 0.0:
70 if ratio < -tol:
71 sys.stderr.write('warning: negative ratio (%s/%s)\n' % (numerator, denominator))
72 return 0.0
73 if ratio > 1.0:
74 if ratio > 1.0 + tol:
75 sys.stderr.write('warning: ratio greater than one (%s/%s)\n' % (numerator, denominator))
76 return 1.0
77 return ratio
78
79
80class UndefinedEvent(Exception):

Callers 4

call_ratiosMethod · 0.85
ratioMethod · 0.85
parseMethod · 0.85

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected