Skip to content
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

Document the behaviour of int("NaN") #22227

Open
wants to merge 3 commits into
base: blead
Choose a base branch
from
Open

Conversation

choroba
Copy link
Contributor

@choroba choroba commented May 21, 2024

There are still people surprised by it, e.g.
https://www.perlmonks.org/?node_id=11159579

pod/perlfunc.pod Outdated
the L<C<sprintf>|/sprintf FORMAT, LIST>,
because it's really more like -268.99999999999994315658 instead.
Similarly, C<int "Info"> produces Inf, see
L<perldata/Special floating point: infinity (Inf) and not-a-number (NaN)>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really "similar" to the above? Floating point accuracy seems unrelated to how Perl doesn't force the result of int to be an integer.

While the link addresses the string conversion to a float, nothing in it or this text address how for numbers outside the integer range, perl will still return a float. And while mathematically 1e50 is an integer even if internally stored as a float, Inf and NaN are definitely not integers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's similar because it "can sometimes produce counterintuitive results". But I agree the wording could be improved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated with a fixup. Let me know if I should squash the changes.

@haarg
Copy link
Contributor

haarg commented May 23, 2024

The change here seems to be trying to document two issues at the same time.

It's documenting that "Info" gets numified into inf, but this has little to do with int. It's also documenting that int(inf) still produces an inf. That seems like the relevant thing to be focusing on here. I feel like using int("Info") rather than int("Inf") makes the docs more confusing.

@choroba
Copy link
Contributor Author

choroba commented May 23, 2024

Ok, removed the "o" in "Info". Another fixup.

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

Successfully merging this pull request may close these issues.

None yet

3 participants