]> git.ipfire.org Git - thirdparty/glibc.git/blob - manual/libm-err-tab.pl
Add fromfp functions.
[thirdparty/glibc.git] / manual / libm-err-tab.pl
1 #!/usr/bin/perl -w
2 # Copyright (C) 1999-2016 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Andreas Jaeger <aj@suse.de>, 1999.
5
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.
10
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.
15
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
19
20 # Information about tests are stored in: %results
21 # $results{$test}{"type"} is the result type, e.g. normal or complex.
22 # In the following description $platform, $type and $float are:
23 # - $platform is the used platform
24 # - $type is either "normal", "real" (for the real part of a complex number)
25 # or "imag" (for the imaginary part # of a complex number).
26 # - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
27 # It represents the underlying floating point type (float, double or long
28 # double) and if inline functions (the leading i stands for inline)
29 # are used.
30 # $results{$test}{$platform}{$type}{$float} is defined and has a delta
31 # or 'fail' as value.
32
33 use File::Find;
34
35 use strict;
36
37 use vars qw ($sources @platforms %pplatforms);
38 use vars qw (%results @all_floats %suffices @all_functions);
39
40
41 # all_floats is in output order and contains all recognised float types that
42 # we're going to output
43 @all_floats = ('float', 'double', 'ldouble');
44 %suffices =
45 ( 'float' => 'f',
46 'double' => '',
47 'ldouble' => 'l'
48 );
49
50 # Pretty description of platform
51 %pplatforms = ();
52
53 @all_functions =
54 ( "acos", "acosh", "asin", "asinh", "atan", "atanh",
55 "atan2", "cabs", "cacos", "cacosh", "carg", "casin", "casinh",
56 "catan", "catanh", "cbrt", "ccos", "ccosh", "ceil", "cexp", "cimag",
57 "clog", "clog10", "conj", "copysign", "cos", "cosh", "cpow", "cproj",
58 "creal", "csin", "csinh", "csqrt", "ctan", "ctanh", "erf", "erfc",
59 "exp", "exp10", "exp2", "expm1", "fabs", "fdim", "floor", "fma",
60 "fmax", "fmaxmag", "fmin", "fminmag", "fmod", "frexp", "fromfp", "fromfpx",
61 "gamma", "hypot",
62 "ilogb", "j0", "j1", "jn", "lgamma", "llogb", "lrint",
63 "llrint", "log", "log10", "log1p", "log2", "logb", "lround",
64 "llround", "modf", "nearbyint", "nextafter", "nextdown", "nexttoward",
65 "nextup", "pow", "remainder", "remquo", "rint", "round", "roundeven",
66 "scalb", "scalbn", "sin", "sincos", "sinh", "sqrt", "tan", "tanh",
67 "tgamma", "trunc", "ufromfp", "ufromfpx", "y0", "y1", "yn" );
68 # canonicalize, fpclassify, getpayload, iscanonical, isnormal,
69 # isfinite, isinf, isnan, issignaling, issubnormal, iszero, signbit,
70 # iseqsig, isgreater, isgreaterequal, isless, islessequal,
71 # islessgreater, isunordered, setpayload, setpayloadsig,
72 # totalorder, totalordermag
73 # are not tabulated.
74
75 if ($#ARGV == 0) {
76 $sources = $ARGV[0];
77 } else {
78 $sources = '/usr/src/cvs/libc';
79 }
80
81 find (\&find_files, $sources);
82
83 @platforms = sort by_platforms @platforms;
84
85 &print_all;
86
87 sub find_files {
88 if ($_ eq 'libm-test-ulps') {
89 # print "Parsing $File::Find::name\n";
90 push @platforms, $File::Find::dir;
91 my ($file, $name);
92 $file = "${File::Find::name}-name";
93 open NAME, $file or die ("Can't open $file: $!");
94 $name = <NAME>;
95 chomp $name;
96 close NAME;
97 $pplatforms{$File::Find::dir} = $name;
98 &parse_ulps ($File::Find::name, $File::Find::dir);
99 }
100 }
101
102 # Parse ulps file
103 sub parse_ulps {
104 my ($file, $platform) = @_;
105 my ($test, $type, $float, $eps);
106
107 # $type has the following values:
108 # "normal": No complex variable
109 # "real": Real part of complex result
110 # "imag": Imaginary part of complex result
111 open ULP, $file or die ("Can't open $file: $!");
112 while (<ULP>) {
113 chop;
114 # ignore comments and empty lines
115 next if /^#/;
116 next if /^\s*$/;
117 if (/^Function: /) {
118 if (/Real part of/) {
119 s/Real part of //;
120 $type = 'real';
121 } elsif (/Imaginary part of/) {
122 s/Imaginary part of //;
123 $type = 'imag';
124 } else {
125 $type = 'normal';
126 }
127 ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
128 next;
129 }
130 if (/^i?(float|double|ldouble):/) {
131 ($float, $eps) = split /\s*:\s*/,$_,2;
132 if ($eps eq 'fail') {
133 $results{$test}{$platform}{$type}{$float} = 'fail';
134 } elsif ($eps eq "0") {
135 # ignore
136 next;
137 } elsif (!exists $results{$test}{$platform}{$type}{$float}
138 || $results{$test}{$platform}{$type}{$float} ne 'fail') {
139 $results{$test}{$platform}{$type}{$float} = $eps;
140 }
141 if ($type =~ /^real|imag$/) {
142 $results{$test}{'type'} = 'complex';
143 } elsif ($type eq 'normal') {
144 $results{$test}{'type'} = 'normal';
145 }
146 next;
147 }
148 print "Skipping unknown entry: `$_'\n";
149 }
150 close ULP;
151 }
152
153 sub get_value {
154 my ($fct, $platform, $type, $float) = @_;
155
156 return (exists $results{$fct}{$platform}{$type}{$float}
157 ? $results{$fct}{$platform}{$type}{$float} : "0");
158 }
159
160 sub print_platforms {
161 my (@p) = @_;
162 my ($fct, $platform, $float, $first, $i, $platform_no, $platform_total);
163
164 print '@multitable {nexttowardf} ';
165 foreach (@p) {
166 print ' {1000 + i 1000}';
167 }
168 print "\n";
169
170 print '@item Function ';
171 foreach (@p) {
172 print ' @tab ';
173 print $pplatforms{$_};
174 }
175 print "\n";
176
177
178 foreach $fct (@all_functions) {
179 foreach $float (@all_floats) {
180 print "\@item $fct$suffices{$float} ";
181 foreach $platform (@p) {
182 print ' @tab ';
183 if (exists $results{$fct}{$platform}{'normal'}{$float}
184 || exists $results{$fct}{$platform}{'real'}{$float}
185 || exists $results{$fct}{$platform}{'imag'}{$float}) {
186 if ($results{$fct}{'type'} eq 'complex') {
187 print &get_value ($fct, $platform, 'real', $float),
188 ' + i ', &get_value ($fct, $platform, 'imag', $float);
189 } else {
190 print $results{$fct}{$platform}{'normal'}{$float};
191 }
192 } else {
193 print '-';
194 }
195 }
196 print "\n";
197 }
198 }
199
200 print "\@end multitable\n";
201 }
202
203 sub print_all {
204 my ($i, $max);
205
206 my ($columns) = 5;
207
208 # Print only 5 platforms at a time.
209 for ($i=0; $i < $#platforms; $i+=$columns) {
210 $max = $i+$columns-1 > $#platforms ? $#platforms : $i+$columns-1;
211 print_platforms (@platforms[$i .. $max]);
212 }
213 }
214
215 sub by_platforms {
216 return $pplatforms{$a} cmp $pplatforms{$b};
217 }