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
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
#!/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__
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!