~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/sort-float.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Ensure sort -g sorts floating point limits correctly
 
3
 
 
4
# Copyright (C) 2010-2012 Free Software Foundation, Inc.
 
5
 
 
6
# This program is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
 
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
 
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
20
print_ver_ sort
 
21
 
 
22
# Return 0 if LDBL_MIN is smaller than DBL_MIN, else 1.
 
23
# Dissect numbers like these, comparing first exponent, then
 
24
# whole part of mantissa, then fraction, until finding enough
 
25
# of a difference to determine the relative order of the numbers.
 
26
# These are "reversed":
 
27
#   $ ./getlimits |grep DBL_MIN
 
28
#   DBL_MIN=2.225074e-308
 
29
#   LDBL_MIN=2.004168e-292
 
30
#
 
31
# These are in the expected order:
 
32
#   $ ./getlimits|grep DBL_MIN
 
33
#   DBL_MIN=2.225074e-308
 
34
#   LDBL_MIN=3.362103e-4932
 
35
 
 
36
dbl_minima_order()
 
37
{
 
38
  LC_ALL=C getlimits_
 
39
  set -- $(echo $LDBL_MIN | tr .e- '   ')
 
40
  local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3
 
41
 
 
42
  set -- $(echo $DBL_MIN |tr .e- '   ')
 
43
  local dbl_whole=$1 dbl_frac=$2 dbl_exp=$3
 
44
 
 
45
  test "$dbl_exp"    -lt "$ldbl_exp"   && return 0
 
46
  test "$ldbl_exp"   -lt "$dbl_exp"    && return 1
 
47
  test "$ldbl_whole" -lt "$dbl_whole"  && return 0
 
48
  test "$dbl_whole"  -lt "$ldbl_whole" && return 1
 
49
  test "$ldbl_frac"  -le "$dbl_frac"   && return 0
 
50
  return 1
 
51
}
 
52
 
 
53
# On some systems, DBL_MIN < LDBL_MIN.  Detect that.
 
54
dbl_minima_order; reversed=$?
 
55
 
 
56
for LOC in C $LOCALE_FR; do
 
57
 
 
58
  LC_ALL=$LOC getlimits_
 
59
 
 
60
  # See if sort should be using long doubles
 
61
  grep '^#define HAVE_C99_STRTOLD 1' $CONFIG_HEADER > /dev/null ||
 
62
    { LDBL_MAX="$DBL_MAX"; LDBL_MIN="$DBL_MIN"; }
 
63
 
 
64
  # If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
 
65
  # so that out expected output is sorted.
 
66
  if test $reversed = 1; then
 
67
    t=$LDBL_MIN
 
68
    LDBL_MIN=$DBL_MIN
 
69
    DBL_MIN=$t
 
70
  fi
 
71
 
 
72
  printf -- "\
 
73
-$LDBL_MAX
 
74
-$DBL_MAX
 
75
-$FLT_MAX
 
76
-$FLT_MIN
 
77
-$DBL_MIN
 
78
-$LDBL_MIN
 
79
0
 
80
$LDBL_MIN
 
81
$DBL_MIN
 
82
$FLT_MIN
 
83
$FLT_MAX
 
84
$DBL_MAX
 
85
$LDBL_MAX
 
86
" |
 
87
  grep '^[0-9.,e+-]*$' > exp # restrict to numeric just in case
 
88
 
 
89
  tac exp | LC_ALL=$LOC sort -sg > out || fail=1
 
90
 
 
91
  compare exp out || fail=1
 
92
done
 
93
 
 
94
Exit $fail