Title: Decide the fate of missing C99 functions in `math` · Issue #135853 · python/cpython · GitHub
Open Graph Title: Decide the fate of missing C99 functions in `math` · Issue #135853 · python/cpython
X Title: Decide the fate of missing C99 functions in `math` · Issue #135853 · python/cpython
Description: Feature or enhancement Proposal: I will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discussed a bit more in detail elsewhere. There are some...
Open Graph Description: Feature or enhancement Proposal: I will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discussed a bit ...
X Description: Feature or enhancement Proposal: I will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discusse...
Opengraph URL: https://github.com/python/cpython/issues/135853
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Decide the fate of missing C99 functions in `math`","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nI will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discussed a bit more in detail elsewhere.\n\nThere are some functions in `math.h` that we don't export in `math` as some are useless for Python or just forgotten. We recently added `isnormal` and `issubnormal` but the following are missing:\n\n#### [`scalbn`](https://www.cppreference.com/w/c/numeric/math/scalbn.html)\n\nIt's only useful if FLT_RADIX != 2. Python only supports FLT_RADIX = 2 or 16 but I don't know how many systems have FLT_RADIX = 16. So I don't think we need it for now. [`logb`](https://www.cppreference.com/w/c/numeric/math/logb.html) also depends on FLT_RADIX but I think we can ignore it if we don't add `scalbn`.\n\n**DECISION**: let's not add it as numpy doesn't have it and it has a confusing name (at least to me).\n\n#### [`fdim`](https://www.cppreference.com/w/c/numeric/math/fdim.html)\n\nThis one could be useful to handle possible signed zeros when doing fp artihmetic. Similarly, `math` currently lacks `fmax` and `fmin` which could useful if we support IEC 60559 because `max(nan, inf) == nan` and `max(inf, nan) == inf` which is incorrect (in both cases `fmax` would have returned `inf` on such systems).\n\n**DECISION**: numpy has `fmax` and `fmin` and treat the NaNs correctly, but not `fdim`. For now, let's not add it.\n\n#### [`remquo`](https://www.cppreference.com/w/c/numeric/math/remquo.html)\n\nThis one is useful for implementing $t$-periodic functions for $t$ exactly representable as an fp-value. I don't know if users are expected to actually work in Python for such functions, but I think we can expose it.\n\n**DECISION**: numpy doesn't have it and while it could be fine, it's actually really niche.\n\n#### [`fpclassify`](https://www.cppreference.com/w/c/numeric/math/fpclassify.html)\n\nNow that we have normal and subnormal detection, I suggest we also add this function. This would however require new constants which may or may not be adequate as this would make the module a bit heavier. It was asked in https://github.com/python/cpython/issues/132908#issuecomment-2834032127 but we didn't follow up with that later.\n\n**DECISION**: I would personally like it but it would more for completeness rather than usefulness, and numpy doesn't have it so I won't push for it.\n\n#### [`isunordered`](https://www.cppreference.com/w/c/numeric/math/isunordered.html)\n\nCan be useful to detect if either operand is a NaN. It can save some `math.isnan(x) or math.isnan(y)` expression.\n\n**DECISION**: it is useful but a better named helper in pure Python would do the job.\n\n#### [`signbit`](https://en.cppreference.com/w/c/numeric/math/signbit) \n\nUseful for getting the sign of signed zeroes, infinities and NaN.\n\n**DECISION**: I was wrong in my original statement as Mark pointed out but this one seems the most useful. So I'll work on it tomorrow.\n\n-----\n\nI omitted some functions such as `isless` as they are directly implemented in Python and I don't think we should do something here. I also omitted rounding functions that depend on the rounding mode as those should be handled by `Decimal` instead. \n\nFinally, it's unfortunate that we named `math.gamma` instead of `math.tgamma` as `math.gamma` could have been confused with Euler-Mascheroni's constant. \n\ncc @skirpichev @tim-one \n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-135877\n* gh-135888\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/picnixz","@type":"Person","name":"picnixz"},"datePublished":"2025-06-23T13:36:07Z","url":"https://github.com/python/cpython/issues/135853"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:30004c53-f1c5-090e-7b90-1c71032839b4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B42C:215B92:34FCD0F:469184E:6B020285 |
| html-safe-nonce | 9b512fbf8629ea46e9c85ede0f918606aa67cdf6d6d5f9ded1361cc83b635c13 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDJDOjIxNUI5MjozNEZDRDBGOjQ2OTE4NEU6NkIwMjAyODUiLCJ2aXNpdG9yX2lkIjoiNjkyOTU1NTA2MjQxOTIyNzI2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fbe57c8faf412099e5d141b9d87f79930d94a999345502df8873cfbfadc85688 |
| hovercard-subject-tag | issue:3168239691 |
| 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/135853/issue_layout |
| twitter:image | https://opengraph.githubassets.com/923dce8520c9c38aeaa453efe7700fbf7c040bb5bc46fc1e7ab1c0981437ccd4/python/cpython/issues/135853 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/923dce8520c9c38aeaa453efe7700fbf7c040bb5bc46fc1e7ab1c0981437ccd4/python/cpython/issues/135853 |
| og:image:alt | Feature or enhancement Proposal: I will first post here because I don't want to flood DPO with a controversial thread. I didn't dig much in the issues so it might have already been discussed a bit ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | picnixz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width