(x, tol)
| 9 | |
| 10 | |
| 11 | def round_to_power_of_two(x, tol): |
| 12 | approxs = [] |
| 13 | for i in range(math.ceil(math.log2(x))): |
| 14 | mult = 2**i |
| 15 | approxs.append(round(x / mult) * mult) |
| 16 | for approx in reversed(approxs): |
| 17 | error = abs((approx - x) / x) |
| 18 | if error <= tol: |
| 19 | return approx |
| 20 | return approxs[0] |
| 21 | |
| 22 | |
| 23 | def load_config(path_or_dict): |