[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
numeric sort gives incorrect result with comparing different formatted f
From: |
Simon Oosthoek |
Subject: |
numeric sort gives incorrect result with comparing different formatted floating point numbers |
Date: |
Mon, 01 Mar 2004 13:09:13 +0100 |
User-agent: |
Mozilla Thunderbird 0.5 (X11/20040208) |
address@hidden on 2004-03-01 11:29 AM Long Description
When sorting the data below (which is already sorted by sort) using "sort
-n" which should numerically sort on the first column (equiv to sort -n
-k 1)
gives inconsistent output w.r.t numbers with missing digits.
This output is derived from ns-2 simulator output, which outputs floating
point numbers in a variety of ways (including exponential formatting). So I
figure sort -n doesn't convert the data to be sorted to a floating point
number. This bug should probably be filed upstream, but I thought I'd start
here first...
---------------------------------------
20.366 1 81 4962 3957
20.368 2 157 5633 18345
20.372 1 81 5155 4082 <-----
20.37 4 116 5573 2057 <-----
20.374 1 57 4962 3958
20.376 2 116 5633 18348
20.378 4 116 5573 2059
20.38 1 57 4962 3959 <-----
20.382 2 116 5633 18350 <-----
20.384 4 116 5573 2061
20.386 1 47 4962 3960
20.388 2 99 5633 18352
20.392 2 81 5633 18354 <--------
20.39 4 157 5573 2063 <------
20.394 2 116 5633 18350
------ Additional comments from address@hidden on
2004-03-01 01:04 PM ------
in the sort.c code, I see this comment, which could explain the problems
I see:
static int
general_numcompare (const char *sa, const char *sb)
{
/* FIXME: add option to warn about failed conversions. */
/* FIXME: maybe add option to try expensive FP conversion
only if A and B can't be compared more cheaply/accurately. */
- numeric sort gives incorrect result with comparing different formatted floating point numbers,
Simon Oosthoek <=