| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added as_integer_ratio to ints to make them more interoperable with floats. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -5260,6 +5260,36 @@ long_is_finite(PyObject *v) | |
| } | ||
| #endif | ||
|
|
||
| /*[clinic input] | ||
| int.as_integer_ratio | ||
|
|
||
| Return integer ratio. | ||
|
|
||
| Return a pair of integers, whose ratio is exactly equal to the original int | ||
| and with a positive denominator. | ||
|
|
||
| >>> (10).as_integer_ratio() | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDo we need so much examples in a docstring?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think it's useful to have at least one positive and one negative example, so that it's obvious at a glance that the behaviour for negatives is to give (for example) (-5, 1) rather than (5, -1). I could imagine users thinking that 0 was somehow a special case, too, so I like that we have the 0 example there.
Sorry, something went wrong.
All reactions
|
||
| (10, 1) | ||
| >>> (-10).as_integer_ratio() | ||
| (-10, 1) | ||
| >>> (0).as_integer_ratio() | ||
| (0, 1) | ||
| [clinic start generated code]*/ | ||
|
|
||
| static PyObject * | ||
| int_as_integer_ratio_impl(PyObject *self) | ||
| /*[clinic end generated code: output=e60803ae1cc8621a input=55ce3058e15de393]*/ | ||
| { | ||
| if PyLong_CheckExact(self) { | ||
| return PyTuple_Pack(2, self, _PyLong_One); | ||
| } else { | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityelse { should be on the next line per PEP 7.
Sorry, something went wrong.
serhiy-storchaka reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMissing parens on the if too
Sorry, something went wrong.
serhiy-storchaka reacted with thumbs up emoji
All reactions
|
||
| PyObject *numerator = _PyLong_Copy(self); | ||
|
Comment thread
eric-wieser marked this conversation as resolved.
|
||
| PyObject *ratio_tuple = PyTuple_Pack(2, numerator, _PyLong_One); | ||
| Py_DECREF(numerator); | ||
| return ratio_tuple; | ||
| } | ||
|
Comment thread
rhettinger marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /*[clinic input] | ||
| int.to_bytes | ||
|
|
||
| Expand Down Expand Up | @@ -5392,6 +5422,7 @@ static PyMethodDef long_methods[] = { | |
| #endif | ||
| INT_TO_BYTES_METHODDEF | ||
| INT_FROM_BYTES_METHODDEF | ||
| INT_AS_INTEGER_RATIO_METHODDEF | ||
| {"__trunc__", long_long_meth, METH_NOARGS, | ||
| "Truncating an Integral returns itself."}, | ||
| {"__floor__", long_long_meth, METH_NOARGS, | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAdd links:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.