Skip Menu |
 

This queue is for tickets about the Sort-Naturally CPAN distribution.

Report information
The Basics
Id: 77627
Status: open
Priority: 0/
Queue: Sort-Naturally

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc: srezic [...] iconmobile.com
tsibley [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 1.02
  • 1.03
Fixed in: (no value)



CC: srezic [...] iconmobile.com
Subject: Wrong sorting of negative or float numbers
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1338891211-5049-2"
Content-Length: 0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 292
Download (untitled) / with headers
text/plain 292b
See the attached test script. It seems that negative integers are not compared correctly, and some float numbers also not. Maybe it would help here if instead of using regexps to check if a value is a number the function Scalar::Util::looks_like_number is used instead? Regards, Slaven
Subject: num_ncmp.t
MIME-Version: 1.0
Content-Type: application/x-troff; name="num_ncmp.t"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="num_ncmp.t"
Content-Transfer-Encoding: base64
Content-Length: 839
Download num_ncmp.t
text/x-perl 839b
#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use Sort::Naturally 'ncmp'; diag "Sort::Natually $Sort::Naturally::VERSION"; sub testcmp ($$$) { my($got, $expected, $testname) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; is ncmp($got,$expected), ($got <=> $expected), $testname; } testcmp 1, 2, 'ncmp with positive integers'; testcmp -1, 2, 'ncmp with mixed integers'; testcmp 1, -2, 'ncmp with mixed integers'; testcmp -1, -2, 'ncmp with negative integers'; testcmp 0.8, 0.085, 'ncmp with positive floats'; testcmp 0.085, 0.8, 'ncmp with positive floats'; testcmp -0.8, 0.085, 'ncmp with mixed floats'; testcmp 0.085, -0.8, 'ncmp with mixed floats'; testcmp -0.8, -0.085, 'ncmp with negative floats'; testcmp -0.085, -0.8, 'ncmp with negative floats'; __END__
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-18436-1408660575-0.77627-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 798
Download (untitled) / with headers
text/plain 798b
On Tue Jun 05 03:13:31 2012, SREZIC wrote: Show quoted text
> See the attached test script. It seems that negative integers are not > compared correctly, and some float numbers also not.
I, too, would like to see negatives and floats supported, but that they are not is documented in the description of the sort routine in the module's POD: · I define "numeric substring" just as sequences matching m/\d+/ -- scientific notation, commas, decimals, etc., are not seen. If your data has thousands separators in numbers ("20,000 Leagues Under The Sea" or "20.000 lieues sous les mers"), consider stripping them before feeding them to "nsort" or "ncmp". I suspect changing it is not in the cards for this module, though I'd certainly like to see support for it!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.