Update.
[glibc.git] / manual / libm-err-tab.pl
blob3357d1855ec2a15a49954f08be64ed72128a3a91
1 #!/usr/bin/perl -w
2 # Copyright (C) 1999, 2001 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Andreas Jaeger <aj@suse.de>, 1999.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library 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 GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, write to the Free
18 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # 02111-1307 USA.
21 # Information about tests are stored in: %results
22 # $results{$test}{"type"} is the result type, e.g. normal or complex.
23 # In the following description $platform, $type and $float are:
24 # - $platform is the used platform
25 # - $type is either "normal", "real" (for the real part of a complex number)
26 # or "imag" (for the imaginary part # of a complex number).
27 # - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
28 # It represents the underlying floating point type (float, double or long
29 # double) and if inline functions (the leading i stands for inline)
30 # are used.
31 # $results{$test}{$platform}{$type}{$float} is defined and has a delta
32 # or 'fail' as value.
34 use File::Find;
36 use strict;
38 use vars qw ($sources @platforms %pplatforms);
39 use vars qw (%results @all_floats %suffices @all_functions);
42 # all_floats is in output order and contains all recognised float types that
43 # we're going to output
44 @all_floats = ('float', 'double', 'ldouble');
45 %suffices =
46 ( 'float' => 'f',
47 'double' => '',
48 'ldouble' => 'l'
51 # Pretty description of platform
52 %pplatforms =
53 ( "i386/fpu" => "ix86",
54 "generic" => "Generic",
55 "alpha" => "Alpha"
58 @all_functions =
59 ( "acos", "acosh", "asin", "asinh", "atan", "atanh",
60 "atan2", "cabs", "cacos", "cacosh", "carg", "casin", "casinh",
61 "catan", "catanh", "cbrt", "ccos", "ccosh", "ceil", "cexp", "cimag",
62 "clog", "clog10", "conj", "copysign", "cos", "cosh", "cpow", "cproj",
63 "creal", "csin", "csinh", "csqrt", "ctan", "ctanh", "erf", "erfc",
64 "exp", "exp10", "exp2", "expm1", "fabs", "fdim", "floor", "fma",
65 "fmax", "fmin", "fmod", "frexp", "gamma", "hypot",
66 "ilogb", "j0", "j1", "jn", "lgamma", "lrint",
67 "llrint", "log", "log10", "log1p", "log2", "logb", "lround",
68 "llround", "modf", "nearbyint", "nextafter", "nexttoward", "pow",
69 "remainder", "remquo", "rint", "round", "scalb", "scalbn", "scalbln",
70 "sin", "sincos", "sinh", "sqrt", "tan", "tanh", "tgamma",
71 "trunc", "y0", "y1", "yn" );
72 # "fpclassify", "isfinite", "isnormal", "signbit" are not tabulated
74 if ($#ARGV == 0) {
75 $sources = $ARGV[0];
76 } else {
77 $sources = '/usr/src/cvs/libc';
80 find (\&find_files, $sources);
82 &print_all;
84 sub find_files {
85 if ($_ eq 'libm-test-ulps') {
86 # print "Parsing $File::Find::name\n";
87 push @platforms, $File::Find::dir;
88 &parse_ulps ($File::Find::name, $File::Find::dir);
92 # Parse ulps file
93 sub parse_ulps {
94 my ($file, $platform) = @_;
95 my ($test, $type, $float, $eps, $kind);
97 # $type has the following values:
98 # "normal": No complex variable
99 # "real": Real part of complex result
100 # "imag": Imaginary part of complex result
101 open ULP, $file or die ("Can't open $file: $!");
102 while (<ULP>) {
103 chop;
104 # ignore comments and empty lines
105 next if /^#/;
106 next if /^\s*$/;
107 if (/^Test/) {
108 $kind = 'test';
109 next;
111 if (/^Function: /) {
112 if (/Real part of/) {
113 s/Real part of //;
114 $type = 'real';
115 } elsif (/Imaginary part of/) {
116 s/Imaginary part of //;
117 $type = 'imag';
118 } else {
119 $type = 'normal';
121 ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
122 $kind = 'fct';
123 next;
125 # Only handle maximal errors of functions
126 next if ($kind eq 'test');
127 if (/^i?(float|double|ldouble):/) {
128 ($float, $eps) = split /\s*:\s*/,$_,2;
129 if ($eps eq 'fail') {
130 $results{$test}{$platform}{$type}{$float} = 'fail';
131 } elsif ($eps eq "0") {
132 # ignore
133 next;
134 } elsif (!exists $results{$test}{$platform}{$type}{$float}
135 || $results{$test}{$platform}{$type}{$float} ne 'fail') {
136 $results{$test}{$platform}{$type}{$float} = $eps;
138 if ($type =~ /^real|imag$/) {
139 $results{$test}{'type'} = 'complex';
140 } elsif ($type eq 'normal') {
141 $results{$test}{'type'} = 'normal';
143 next;
145 print "Skipping unknown entry: `$_'\n";
147 close ULP;
150 sub get_value {
151 my ($fct, $platform, $type, $float) = @_;
153 return (exists $results{$fct}{$platform}{$type}{$float}
154 ? $results{$fct}{$platform}{$type}{$float} : "0");
157 sub canonicalize_platform {
158 my ($platform) = @_;
160 $platform =~ s|^(.*/sysdeps/)||;
163 return exists $pplatforms{$platform} ? $pplatforms{$platform} : $platform;
166 sub print_all {
167 my ($fct, $platform, $float, $first, $i);
169 print '@multitable {nexttowardf} ';
170 foreach (@platforms) {
171 print ' {1000 + i 1000}';
173 print "\n";
175 print '@item Function ';
176 foreach (@platforms) {
177 print ' @tab ';
178 print &canonicalize_platform ($_);
180 print "\n";
183 foreach $fct (@all_functions) {
184 foreach $float (@all_floats) {
185 print "\@item $fct$suffices{$float} ";
186 foreach $platform (@platforms) {
187 print ' @tab ';
188 if (exists $results{$fct}{$platform}{'normal'}{$float}
189 || exists $results{$fct}{$platform}{'real'}{$float}
190 || exists $results{$fct}{$platform}{'imag'}{$float}) {
191 if ($results{$fct}{'type'} eq 'complex') {
192 print &get_value ($fct, $platform, 'real', $float),
193 ' + i ', &get_value ($fct, $platform, 'imag', $float);
194 } else {
195 print $results{$fct}{$platform}{'normal'}{$float};
197 } else {
198 print '-';
201 print "\n";
205 print "\@end multitable\n";