GNU bug report logs - #66256
sorting NAN values with "general-numeric’

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: Jorge Stolfi <stolfi@HIDDEN>; dated Thu, 28 Sep 2023 11:16:02 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at submit <at>

Received: (at submit) by; 28 Sep 2023 11:15:35 +0000
From debbugs-submit-bounces <at> Thu Sep 28 07:15:35 2023
Received: from localhost ([]:53149
	by with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at>>)
	id 1qlozV-0006jY-PX
	for submit <at>; Thu, 28 Sep 2023 07:15:35 -0400
Received: from ([2001:470:142::17]:50292)
 by with esmtp (Exim 4.84_2)
 (envelope-from <stolfi@HIDDEN>) id 1qloVL-0005lT-EG
 for submit <at>; Thu, 28 Sep 2023 06:44:24 -0400
Received: from ([2001:470:142:3::10])
 by with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <stolfi@HIDDEN>)
 id 1qloV1-0003f6-Dv
 for bug-coreutils@HIDDEN; Thu, 28 Sep 2023 06:44:03 -0400
Received: from ([])
 by with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <stolfi@HIDDEN>)
 id 1qloUw-0003tA-IN
 for bug-coreutils@HIDDEN; Thu, 28 Sep 2023 06:44:00 -0400
Received: from ( [])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested) (Authenticated sender: stolfi)
 by (Postfix) with ESMTPSA id 9E87A27C4E4A
 for <bug-coreutils@HIDDEN>; Thu, 28 Sep 2023 07:43:53 -0300 (-03)
DKIM-Filter: OpenDKIM Filter v2.11.0 9E87A27C4E4A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;;
 s=default; t=1695897833;
Received: from
 ( []) by (Horde Framework) with HTTPS; Thu, 28 Sep 2023
 07:43:52 -0300
Date: Thu, 28 Sep 2023 07:43:52 -0300
Message-ID: <20230928074352.Horde.e6lnpeLVHKt8TsI8KnyEFB1@HIDDEN>
From: Jorge Stolfi <stolfi@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: sorting NAN values with =?utf-8?b?ImdlbmVyYWwtbnVtZXJpY+KAmQ==?=
User-Agent: Horde Application Framework 5
Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes
MIME-Version: 1.0
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=; envelope-from=stolfi@HIDDEN;
X-Spam_score_int: -19
X-Spam_score: -2.0
X-Spam_bar: --
X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 28 Sep 2023 07:15:28 -0400
X-BeenThere: debbugs-submit <at>
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <>
List-Unsubscribe: <>, 
 <mailto:debbugs-submit-request <at>>
List-Archive: <>
List-Post: <mailto:debbugs-submit <at>>
List-Help: <mailto:debbugs-submit-request <at>>
List-Subscribe: <>, 
 <mailto:debbugs-submit-request <at>>
Errors-To: debbugs-submit-bounces <at>
Sender: "Debbugs-submit" <debbugs-submit-bounces <at>>
X-Spam-Score: -0.1 (/)

The full documentation of the "--general-numeric-sort" option of  
{sort} says that NaN values are sorted "in a consistent but  
machine-dependent order".

This is not good. The point of the IEEE floating-point standard was to  
make the results of floating-point computations be independent of the  
platform or implementation.

Please consider extending that goal to the handling of NaNs by {sort}.  
  That it, all flavors of NaN (determined by their char tails, as  
parsed by {strtod}) should be treated as equal.

The fact that different flavors of NaN have distinct binary  
representation is not an excuse to sort them as distinct, since the  
same is true of +0 and -0, which "general-numeric" sort already treats  
as equal.

As a separate suggestion, please consider having {sort} abort with an  
error message if any field that is supposed to be sorted with  
"general-numeric" is not a valid {double} value, or has some leftover  
chars that are not parsed by {strtod}.

Whether these solutions are accepted or not, please change the manpage  
explanation of "-g"/"--general-numeric-sort" to say, at least, "the  
field is parsed as a double-precision (64-bit) floating-point number  
and sorted by its numeric value".

Thanks, and all the best,

Jorge Stolfi - Professor Titular/Full Professor
Instituto de Computação/Computer Science Dept
Universidade Estadual de Campinas/State University of Campinas
Campinas, SP - Brazil

Acknowledgement sent to Jorge Stolfi <stolfi@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#66256; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 28 Sep 2023 11:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.