Subject: Re: sort manpage is obscure on this point
To: None <>
From: Jim Meyering <>
List: current-users
Date: 06/26/1996 17:26:18
From: VaX#n8 <>
Date: Wed, 26 Jun 1996 09:52:33 -0500

| >| What the sort manpage does not say is that it's numeric comparison does
| >| not use atoi() or any of the normal string-to-machine conversions but
| >| rather does it's own (admittedly fast) algorithm.
| >| However, it does not handle leading "+"s very well, where the other ones do.
| >
| >On what system did the vendor-supplied sort -n handle a leading `+'
| >differently?
| Sorry, I meant "the other algorithms", like ato*(3) and friends,
| convert leading "+" properly.
| Also, the algorithm in the GNU sort does not handle a leading "-." (as in
| "-.2")...  the decimal -must- be led by a zero.

You still haven't said what version of GNU sort you're using.
Use sort --version to see.  In the latest (1.18), sort -n properly
handles numbers like `-.2':

  % printf "-.2\n0\n-1\n" |sort -n

| Interestingly, no vendor manpage that I've seen defines the format for such
| numbers, or in any way indicates they don't use ato*(3) and friends.
| Thankfully, there's GNU :)

The man page for GNU sort says this

     -n   Compare  according  to  arithmetic  value  an   initial
          numeric  string  consisting of optional white space, an
          optional - sign, and zero or  more  digits,  optionally
          followed by a decimal point and zero or more digits.

which doesn't *explicitly* say that it uses a nonstandard
method to compare floating point numbers.  But it does imply that,
because (by omission) neither a leading `+' nor exponential
notation is recognized.

I'll change the texinfo documentation to make that explicit.
In fact, sort -n doesn't convert strings to `double' at all.
It actually aligns the decimal points in the two strings and
compares the strings a character at a time.