<div dir="ltr">On Mon, Mar 12, 2018 at 9:18 PM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">[Guido]<br>
> .... as_integer_ratio() seems mostly cute (it has Tim Peters all<br>
> over it),<br>
<br>
Nope!  I had nothing to do with it.  I would have been -0.5 on adding<br>
it had I been aware at the time.<br></blockquote><div><br></div><div>Looks like it snuck into the float type as part of the fractions.Fraction work in <a href="https://bugs.python.org/issue1682">https://bugs.python.org/issue1682</a> . I couldn't find much related discussion; I suspect that the move was primarily for optimization (see <a href="https://github.com/python/cpython/commit/3ea7b41b5805c60a05e697211d0bfc14a62a19fb">https://github.com/python/cpython/commit/3ea7b41b5805c60a05e697211d0bfc14a62a19fb</a>). Decimal.as_integer_ratio was added here: <a href="https://bugs.python.org/issue25928">https://bugs.python.org/issue25928</a> .</div><div><br></div><div>I do have significant uses of `float.as_integer_ratio` in my own code, and wouldn't enjoy seeing it being deprecated/ripped out, though I guess I'd cope.</div><div><br></div><div>Some on this thread have suggested that things like is_integer and as_integer_ratio should be math module functions. Any suggestions for how that might be made to work? Would we special-case the types we know about, and handle only those (so the math module would end up having to know about the fractions and decimal modules)? Or add a new magic method (e.g., __as_integer_ratio__) for each case we want to handle, like we do for math.__floor__, math.__trunc__ and math.__ceil__? Or use some form of single dispatch, so that custom types can register their own handlers? The majority of current math module functions simply convert their arguments to a float, so a naive implementation of math.is_integer in the same style wouldn't work: it would give incorrect results for a non-integral Decimal instance that ended up getting rounded to an integral value by the float conversion.</div><div><br></div><div>Mark</div></div></div></div>