8000 gh-132908: check the return type of isnormal() and issubnormal() by picnixz · Pull Request #136039 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132908: check the return type of isnormal() 8000 and issubnormal() #136039

New issue

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

Closed
wants to merge 1 commit into from

Conversation

picnixz
Copy link
Member
@picnixz picnixz commented Jun 27, 2025

I've actually stumbled upon the isnormal() C11 requirements (which I assume are the same as issubnormal() ones but I don't have a C23 copy) and I think we can add those checks (I first thought about returning the integer value given by signbit but in C++, it returns a bool instead of just an integer [on some implementations it gives the power of 2 representing the sign bit].

Copy link
Contributor
@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but we don't have similar checks for other predicates, e.g. isfinite(). That's why I don't sure we should add such checks.

But it's up to you. BTW, probably you can remove comments - we have documentation, right?

@picnixz
Copy link
Member Author
picnixz commented Jun 27, 2025

That's why I don't sure we should add such checks.

Oh! Ok makes sense. Let's not burden the already existing tests. I've added it in signbit because signbit may return the corresponding power-of-two if there is a sign bit. But I think it's the only one that is not named "isXXX()" and that returns a boolean.

But it's up to you. BTW, probably you can remove comments - we have documentation, right?

Right. I actually wanted to add a comment in the tests in case we change the return value for some reason (it could serve as a regression test as well). I don't want to burden the online docs with those implementation details (in C++ for instance, it's a boolean that is returned, so depending on the page of cppreference you land, you may be like "why are they explaining this?").


Sorry for the noise! I'll keep the check in the signbit PR because of the lack of the is prefix but won't merge this one.

@picnixz picnixz closed this Jun 27, 2025
@picnixz
Copy link
Member Author
picnixz commented Jun 27, 2025

@skirpichev Btw, do you remember if we have an issue about positional-only arguments in math.* ? all functions are positional-only but I don't remember what we decided.

@picnixz picnixz deleted the refactor/test/issnormal-132908 branch June 27, 2025 14:43
@skirpichev
Copy link
Contributor

do you remember if we have an issue about positional-only arguments in math.* ? all functions are positional-only but I don't remember what we decided.

@picnixz, I'm not sure we have an issue about this. Perhaps, you are about this pr: #131886 ?

In similar way we could change signatures in the math module. The cost is a small regression in processing arguments. (Perhaps, it could be solved.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
42D1 None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0