Skip to content

Commit

Permalink
Document the behaviour of int("NaN")
Browse files Browse the repository at this point in the history
There are still people surprised by it, e.g.
https://www.perlmonks.org/?node_id=11159579
  • Loading branch information
E. Choroba committed May 21, 2024
1 parent 1a2e8e7 commit 410dae8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pod/perlfunc.pod
Original file line number Diff line number Diff line change
Expand Up @@ -3773,8 +3773,10 @@ You should not use this function for rounding: one because it truncates
towards C<0>, and two because machine representations of floating-point
numbers can sometimes produce counterintuitive results. For example,
C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
because it's really more like -268.99999999999994315658 instead. Usually,
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)>
for explanation. Usually, the L<C<sprintf>|/sprintf FORMAT, LIST>,
L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
functions will serve you better than will L<C<int>|/int EXPR>.
Expand Down

0 comments on commit 410dae8

Please sign in to comment.