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
"sort { $a <=> $b }" silent on <=> returning non-number #9603
Comments
From @ikegamiCreated by @ikegamiWhen the builtin comparison code for "sort { $a <=> $b }" is used, --- BEGIN CODE --- # I don't know how else to generate a NaN in ActivePerl. { print("Builtin:\n"); my @a = sort { $a <=> $b } 0, $nan; } --- BEGIN OUTPUT --- Perl Info
|
From alex@chmrr.netCreated by alex@chmrr.netSorting a list containing NaN leads to odd results: umgah ~ $ perl -wle 'print for sort {$a <=> $b} (4,6,5,2,NaN,3,1);' Given that NaN, and repeated comparisons to it, is involved, this in Because "<=>" returns "undef" when either operand is "NaN" The promised fatal error does not seem to have appeared. It is Perl Info
|
From @cpansproutOn Fri Jul 08 13:31:48 2011, alex@chmrr.net wrote:
The behaviour of sort with regard to undefined values return from In previous perl versions, the {$a <=> $b} case is specially optimised I have just updated the documentation with commit 1bd4e8e. However, there is still an optimisation bug: $ perl5.12.0 -wle 'print for sort {($a)[0] <=> $b} (4,6,5,2,NaN,3,1);' I’ve just fixed that with commit f3dab52. |
The RT System itself - Status changed from 'new' to 'open' |
@cpansprout - Status changed from 'open' to 'resolved' |
From @cpansproutI made enough mistakes in my message that it’s confusing. On Wed Oct 12 23:29:54 2011, sprout wrote:
s/return\k/ed/
s/produce\kd/s/
s/undef/nan/
|
From @cpansproutAha! This is the same as #94390, which I’ve just fixed. |
@cpansprout - Status changed from 'new' to 'resolved' |
From @cpansproutOn Wed Dec 17 14:35:52 2008, ikegami@adaelis.com wrote:
You can use sin(9**9**9), which produces a negative nan. -sin(...) (See also <https://rt.cpan.org/Public/Bug/Display.html?id=65876>). |
From jpl@research.att.comThere's already a comment in perlfunc.pod warning about sort and NaN. I Because C<< <=> >> returns C<undef> when either operand is C<NaN> @result = sort { $a <=> $b } grep { $_ == $_ } @input; |
Migrated from rt.perl.org#61448 (status was 'resolved')
Searchable as RT61448$
The text was updated successfully, but these errors were encountered: