Title: The return value of function `math.isclose` can be somewhat misleading · Issue #126165 · python/cpython · GitHub
Open Graph Title: The return value of function `math.isclose` can be somewhat misleading · Issue #126165 · python/cpython
X Title: The return value of function `math.isclose` can be somewhat misleading · Issue #126165 · python/cpython
Description: Documentation The following example may be misleading to people who are not familiar with the function: >>> math.isclose(math.sin(0), 0) ... True >>> math.isclose(math.sin(math.pi), 0) ... False >>> To a newbie, the above results seem ri...
Open Graph Description: Documentation The following example may be misleading to people who are not familiar with the function: >>> math.isclose(math.sin(0), 0) ... True >>> math.isclose(math.sin(math.pi), 0) ... False >>...
X Description: Documentation The following example may be misleading to people who are not familiar with the function: >>> math.isclose(math.sin(0), 0) ... True >>> math.isclose(math.sin(math.pi...
Opengraph URL: https://github.com/python/cpython/issues/126165
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The return value of function `math.isclose` can be somewhat misleading","articleBody":"# Documentation\r\n\r\nThe following example may be misleading to people who are not familiar with the function:\r\n\r\n```python\r\n\u003e\u003e\u003e math.isclose(math.sin(0), 0)\r\n... True\r\n\u003e\u003e\u003e math.isclose(math.sin(math.pi), 0)\r\n... False\r\n\u003e\u003e\u003e \r\n```\r\n\r\nTo a newbie, the above results seem ridiculous. Correspondingly, the result in `numpy` is as follows:\r\n\r\n```python\r\n\u003e\u003e\u003e numpy.isclose(math.sin(0), 0)\r\n... np.True_\r\n\u003e\u003e\u003e numpy.isclose(math.sin(math.pi), 0)\r\n... np.True_\r\n\u003e\u003e\u003e \r\n```\r\n\r\nFor reference, some values are given here:\r\n\r\n```python\r\n\u003e\u003e\u003e math.sin(0)\r\n... 0.0\r\n\u003e\u003e\u003e math.sin(math.pi)\r\n... 1.2246467991473532e-16\r\n\u003e\u003e\u003e \r\n```\r\n\r\nI think, the reason for this is that the default value of parameter `abs_tol` for function `math.isclose` is too small. Here are the definitions of the two functions mentioned above:\r\n\r\n```python\r\nmath.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)\r\nnumpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)\r\n```\r\n\r\nI think we might need to state this in the docstring of function `math.isclose`, ~~or increase the value of the default parameter `abs_tol` appropriately.~~\r\n\r\nBy the way, the `numpy` version I'm using here is *v2.1*.\r\n\r\nIf there is something wrong with my previous content, please feel free to point it out, thank you!\r\n\r\n\r\n### CPython versions tested on:\r\n\r\n3.13\r\n\r\n### Operating systems tested on:\r\n\r\nWindows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-126215\n* gh-126380\n* gh-126381\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Xiaokang2022","@type":"Person","name":"Xiaokang2022"},"datePublished":"2024-10-30T03:31:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/126165/cpython/issues/126165"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d2f100f2-862c-408c-6ab9-819cb1890605 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A07C:388B78:DE153E:11F6628:696B0485 |
| html-safe-nonce | fda1efc9cbccdd75442824b11f611b68d9c5aa3c3e858017e6829d1cbd4acdba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDdDOjM4OEI3ODpERTE1M0U6MTFGNjYyODo2OTZCMDQ4NSIsInZpc2l0b3JfaWQiOiI2Mzg5NzcyNjMwNzE3MzAxODkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 342ce72c5b6421c19fe0fbc97d553ad23131b5871feb3391329dabccb970803b |
| hovercard-subject-tag | issue:2622780097 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/126165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5c1d91bb8f003845514b69ff65c88b31aa794e43363c086a111ac8be17e9bc5b/python/cpython/issues/126165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5c1d91bb8f003845514b69ff65c88b31aa794e43363c086a111ac8be17e9bc5b/python/cpython/issues/126165 |
| og:image:alt | Documentation The following example may be misleading to people who are not familiar with the function: >>> math.isclose(math.sin(0), 0) ... True >>> math.isclose(math.sin(math.pi), 0) ... False >>... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Xiaokang2022 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width