Prev: FAQ 8.26 Why doesn't open() return an error when a pipe open fails?
Next: Detecting Bourne (or csh) shell from Perl
From: mdudley on 3 Mar 2010 15:00 Is there any way to sort floating point numbers in perl? Every example I have tried has failed. Numerical sort appears to NOT to be a numerical sort but rather an integer sort. Thanks, Marshall
From: John W. Krahn on 3 Mar 2010 15:41 mdudley wrote: > Is there any way to sort floating point numbers in perl? Every > example I have tried has failed. Numerical sort appears to NOT to be > a numerical sort but rather an integer sort. Perhaps you are sorting them as strings instead of numbers? John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway
From: Steve C on 3 Mar 2010 16:04 mdudley wrote: > Is there any way to sort floating point numbers in perl? Every > example I have tried has failed. Numerical sort appears to NOT to be > a numerical sort but rather an integer sort. > worksforme perl -e 'print join ("\n", sort ( 0.1, 0.7, 0.3, 0.25, 0.5))' 0.1 0.25 0.3 0.5 0.7
From: J�rgen Exner on 3 Mar 2010 16:26 mdudley <mdudley(a)king-cart.com> wrote: >Is there any way to sort floating point numbers in perl? Every >example I have tried has failed. Numerical sort appears to NOT to be >a numerical sort but rather an integer sort. Please post a minimal working sample program including sampe data as needed that demonstrates your problem. Because every example that I have tried has worked just fine. jue
From: Steve C on 3 Mar 2010 16:52
Steve C wrote: > mdudley wrote: >> Is there any way to sort floating point numbers in perl? Every >> example I have tried has failed. Numerical sort appears to NOT to be >> a numerical sort but rather an integer sort. >> > Oops. Forgot about default sort function being string cmp. Although that tends to work in a surprising number of cases. perl -e 'print join ("\n", sort {$a <=> $b} (0.1, 0.7, -0.3, 0.25, 0.5))' -0.3 0.1 0.25 0.5 0.7 |