Here's an excerpted (and slightly simplified for consumption here) usage of float.is_integer() from the top of a function which does some convolution/filtering in a geophysics application. I've mostly seen it used in guard clauses in this way to reject either illegal numeric arguments directly, or particular combinations of arguments as in this case: def filter_convolve(x, y, xf, yf, stride=1, padding=1): x_out = (x - xf + 2*padding) / stride + 1 y_out = (y - yf + 2*padding) / stride + 1 if not (x_out.is_integer() and y_out.is_integer()): raise ValueError("Invalid convolution filter_convolve({x}, {y}, {xf}, {yf}, {stride}, {padding})" .format(x=x, y=y, xf=xf, yf=yf, stride=stride, padding=padding)) x_out = int(x_out) y_out = int(y_out) # ... Of course, there are other ways to do this check, but the approach here is obvious and easy to comprehend. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/c299415c/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4