From: mdudley on
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
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
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
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
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