aboutsummaryrefslogtreecommitdiff
path: root/manual/libm-err-tab.pl
blob: fa10858343f362af2c10939c177fd01ca04282dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/perl -w

# Copyright (C) 1999, 2001 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Andreas Jaeger <aj@suse.de>, 1999.

# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.

# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.

# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB.  If not,
# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# Information about tests are stored in: %results
# $results{$test}{"type"} is the result type, e.g. normal or complex.
# In the following description $platform, $type and $float are:
# - $platform is the used platform
# - $type is either "normal", "real" (for the real part of a complex number)
#   or "imag" (for the imaginary part # of a complex number).
# - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
#   It represents the underlying floating point type (float, double or long
#   double) and if inline functions (the leading i stands for inline)
#   are used.
# $results{$test}{$platform}{$type}{$float} is defined and has a delta
# or 'fail' as value.

use File::Find;

use strict;

use vars qw ($sources @platforms %pplatforms);
use vars qw (%results @all_floats %suffices @all_functions);


# all_floats is in output order and contains all recognised float types that
# we're going to output
@all_floats = ('float', 'double', 'ldouble');
%suffices =
  ( 'float' => 'f',
    'double' => '',
    'ldouble' => 'l'
  );

# Pretty description of platform
%pplatforms =
  ( "i386/fpu" => "ix86",
    "generic" => "Generic",
    "alpha" => "Alpha"
  );

@all_functions = 
  ( "acos", "acosh", "asin", "asinh", "atan", "atanh",
    "atan2", "cabs", "cacos", "cacosh", "carg", "casin", "casinh",
    "catan", "catanh", "cbrt", "ccos", "ccosh", "ceil", "cexp", "cimag",
    "clog", "clog10", "conj", "copysign", "cos", "cosh", "cpow", "cproj",
    "creal", "csin", "csinh", "csqrt", "ctan", "ctanh", "erf", "erfc",
    "exp", "exp10", "exp2", "expm1", "fabs", "fdim", "floor", "fma",
    "fmax", "fmin", "fmod", "frexp", "gamma", "hypot",
    "ilogb", "j0", "j1", "jn", "lgamma", "lrint",
    "llrint", "log", "log10", "log1p", "log2", "logb", "lround",
    "llround", "modf", "nearbyint", "nextafter", "nexttoward", "pow",
    "remainder", "remquo", "rint", "round", "scalb", "scalbn", "scalbln",
    "sin", "sincos", "sinh", "sqrt", "tan", "tanh", "tgamma",
    "trunc", "y0", "y1", "yn" );
# "fpclassify", "isfinite", "isnormal", "signbit" are not tabulated

if ($#ARGV == 0) {
  $sources = $ARGV[0];
} else {
  $sources = '/usr/src/cvs/libc';
}

find (\&find_files, $sources);

&print_all;

sub find_files {
  if ($_ eq 'libm-test-ulps') {
    # print "Parsing $File::Find::name\n";
    push @platforms, $File::Find::dir;
    &parse_ulps ($File::Find::name, $File::Find::dir);
  }
}

# Parse ulps file
sub parse_ulps {
  my ($file, $platform) = @_;
  my ($test, $type, $float, $eps, $kind);

  # $type has the following values:
  # "normal": No complex variable
  # "real": Real part of complex result
  # "imag": Imaginary part of complex result
  open ULP, $file  or die ("Can't open $file: $!");
  while (<ULP>) {
    chop;
    # ignore comments and empty lines
    next if /^#/;
    next if /^\s*$/;
    if (/^Test/) {
      $kind = 'test';
      next;
    }
    if (/^Function: /) {
      if (/Real part of/) {
	s/Real part of //;
	$type = 'real';
      } elsif (/Imaginary part of/) {
	s/Imaginary part of //;
	$type = 'imag';
      } else {
	$type = 'normal';
      }
      ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
      $kind = 'fct';
      next;
    }
    # Only handle maximal errors of functions
    next if ($kind eq 'test');
    if (/^i?(float|double|ldouble):/) {
      ($float, $eps) = split /\s*:\s*/,$_,2;
      if ($eps eq 'fail') {
	$results{$test}{$platform}{$type}{$float} = 'fail';
      } elsif ($eps eq "0") {
	# ignore
	next;
      } elsif (!exists $results{$test}{$platform}{$type}{$float} 
	    || $results{$test}{$platform}{$type}{$float} ne 'fail') {
	$results{$test}{$platform}{$type}{$float} = $eps;
      }
      if ($type =~ /^real|imag$/) {
	$results{$test}{'type'} = 'complex';
      } elsif ($type eq 'normal') {
	$results{$test}{'type'} = 'normal';
      }
      next;
    }
    print "Skipping unknown entry: `$_'\n";
  }
  close ULP;
}

sub get_value {
  my ($fct, $platform, $type, $float) = @_;

  return (exists $results{$fct}{$platform}{$type}{$float} 
	  ? $results{$fct}{$platform}{$type}{$float} : "0");
}

sub canonicalize_platform {
  my ($platform) = @_;

  $platform =~ s|^(.*/sysdeps/)||;


  return exists $pplatforms{$platform} ? $pplatforms{$platform} : $platform;
}

sub print_all {
  my ($fct, $platform, $float, $first, $i);

  print '@multitable {nexttowardf} ';
  foreach (@platforms) {
    print ' {1000 + i 1000}';
  }
  print "\n";

  print '@item Function ';
  foreach (@platforms) {
    print ' @tab ';
    print &canonicalize_platform ($_);
  }
  print "\n";

  
  foreach $fct (@all_functions) {
    foreach $float (@all_floats) {
      print "\@item $fct$suffices{$float} ";
      foreach $platform (@platforms) {
	print ' @tab ';
	if (exists $results{$fct}{$platform}{'normal'}{$float}
	    || exists $results{$fct}{$platform}{'real'}{$float}
	    || exists $results{$fct}{$platform}{'imag'}{$float}) {
	  if ($results{$fct}{'type'} eq 'complex') {
	    print &get_value ($fct, $platform, 'real', $float),
	    ' + i ', &get_value ($fct, $platform, 'imag', $float);
	  } else {
	    print $results{$fct}{$platform}{'normal'}{$float};
	  }
	} else {
	  print '-';
	}
      }
      print "\n";
    }
  }

  print "\@end multitable\n";
}