Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Oct 2011 13:05:42 +0100
From:      Anton Shterenlikht <mexas@bristol.ac.uk>
To:        freebsd-questions@freebsd.org
Subject:   cat sort(1) sort floating point numbers?
Message-ID:  <20111003120542.GA98919@mech-cluster241.men.bris.ac.uk>

Next in thread | Raw E-Mail | Index | Archive | Help
I tried sorting a file with a column of floating
point numbers (below) with sort(1) -n. However, 
the numbers seem to have been sorted by the first
digit only.

TZAV> cat numbers
3.895686170464136E-016
6.790214437463702E-003
4.163481430190832E-016
2.224131318975909E-002
4.024567914829249E-016
3.538878408636508E-016
9.506347960184421E-016
6.314417282585591E-016
1.026969483958696E-015
1.172673069936531E-015
9.367571020052471E-016
1.110223231422310E-016
1.734778989627912E-015
1.942890368732350E-016
1.117248113958902E-015
1.041412167622504E-015
2.985539431996711E-016
1.728132885863794E-015
2.332566825794786E-015
1.991764744128308E-015
2.290886104875174E-015
1.499379464023130E-015
4.749124883992963E-015
1.526556658859590E-016
1.056173107658783E-015
7.245814328704277E-015
3.819445116003758E-015
2.102152816759188E-015
2.721320602617330E-015
3.223263731968939E-015
1.637578979324018E-015
5.858485627624118E-015
4.442648920965769E-015
1.110244709780361E-015
6.664589960756288E-016
9.761199453440974E-017
1.443557048454884E-015
4.778495371619422E-015
1.947840641841358E-016
5.064931302120728E-016
2.916449385533579E-015
8.400504967177337E-017
1.166250379869858E-015
8.331298074911436E-016
8.337074617781950E-016
1.332719331522803E-015
2.332500698909792E-015
9.104042995697664E-015
1.659811850387433E-014
7.774349986542096E-016
3.610152526999016E-015
5.594426896215451E-017
8.329275106256349E-016
3.830369997864534E-015
3.331392089232636E-016
6.664589971819531E-016
9.325914711054265E-015
1.110226687428913E-016
4.443060083949530E-016
1.388403156535668E-015
5.117876306319294E-016
4.443061859904843E-016
1.593208723602013E-014
2.720931336739666E-015
1.110224674090772E-016
3.916020680284665E-016
1.332269256131286E-014
4.441434721463274E-016
2.886880095386799E-015
1.054917340440720E-015
6.938930742946899E-018
8.659917512448818E-015
4.274409407182516E-015
5.551552273367660E-016
7.549545267281662E-015
9.492612312578653E-015
7.772800489254079E-016
2.554043227849122E-015
7.382990493079966E-015
5.722182748984452E-017

TZAV> sort -n numbers
1.026969483958696E-015
1.041412167622504E-015
1.054917340440720E-015
1.056173107658783E-015
1.110223231422310E-016
1.110224674090772E-016
1.110226687428913E-016
1.110244709780361E-015
1.117248113958902E-015
1.166250379869858E-015
1.172673069936531E-015
1.332269256131286E-014
1.332719331522803E-015
1.388403156535668E-015
1.443557048454884E-015
1.499379464023130E-015
1.526556658859590E-016
1.593208723602013E-014
1.637578979324018E-015
1.659811850387433E-014
1.728132885863794E-015
1.734778989627912E-015
1.942890368732350E-016
1.947840641841358E-016
1.991764744128308E-015
2.102152816759188E-015
2.224131318975909E-002
2.290886104875174E-015
2.332500698909792E-015
2.332566825794786E-015
2.554043227849122E-015
2.720931336739666E-015
2.721320602617330E-015
2.886880095386799E-015
2.916449385533579E-015
2.985539431996711E-016
3.223263731968939E-015
3.331392089232636E-016
3.538878408636508E-016
3.610152526999016E-015
3.819445116003758E-015
3.830369997864534E-015
3.895686170464136E-016
3.916020680284665E-016
4.024567914829249E-016
4.163481430190832E-016
4.274409407182516E-015
4.441434721463274E-016
4.442648920965769E-015
4.443060083949530E-016
4.443061859904843E-016
4.749124883992963E-015
4.778495371619422E-015
5.064931302120728E-016
5.117876306319294E-016
5.551552273367660E-016
5.594426896215451E-017
5.722182748984452E-017
5.858485627624118E-015
6.314417282585591E-016
6.664589960756288E-016
6.664589971819531E-016
6.790214437463702E-003
6.938930742946899E-018
7.245814328704277E-015
7.382990493079966E-015
7.549545267281662E-015
7.772800489254079E-016
7.774349986542096E-016
8.329275106256349E-016
8.331298074911436E-016
8.337074617781950E-016
8.400504967177337E-017
8.659917512448818E-015
9.104042995697664E-015
9.325914711054265E-015
9.367571020052471E-016
9.492612312578653E-015
9.506347960184421E-016
9.761199453440974E-017

Is this the expected behaviour?
If yes, can sort(1) be at all
used to sort float. point numbers?

Many thanks
Anton

-- 
Anton Shterenlikht
Room 2.6, Queen's Building
Mech Eng Dept
Bristol University
University Walk, Bristol BS8 1TR, UK
Tel: +44 (0)117 331 5944
Fax: +44 (0)117 929 4423



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20111003120542.GA98919>