]> sourceware.org Git - glibc.git/blob - math/gen-libm-test.pl
Start converting libm tests from code to data.
[glibc.git] / math / gen-libm-test.pl
1 #!/usr/bin/perl -w
2 # Copyright (C) 1999-2013 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 # This file needs to be tidied up
21 # Note that functions and tests share the same namespace.
22
23 # Information about tests are stored in: %results
24 # $results{$test}{"kind"} is either "fct" or "test" and flags whether this
25 # is a maximal error of a function or a single test.
26 # $results{$test}{"type"} is the result type, e.g. normal or complex.
27 # $results{$test}{"has_ulps"} is set if deltas exist.
28 # In the following description $type and $float are:
29 # - $type is either "normal", "real" (for the real part of a complex number)
30 # or "imag" (for the imaginary part # of a complex number).
31 # - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
32 # It represents the underlying floating point type (float, double or long
33 # double) and if inline functions (the leading i stands for inline)
34 # are used.
35 # $results{$test}{$type}{"ulp"}{$float} is defined and has a delta as value
36
37
38 use Getopt::Std;
39
40 use strict;
41
42 use vars qw ($input $output);
43 use vars qw (%results);
44 use vars qw (@tests @functions);
45 use vars qw ($count);
46 use vars qw (%beautify @all_floats);
47 use vars qw ($output_dir $ulps_file);
48
49 # all_floats is sorted and contains all recognised float types
50 @all_floats = ('double', 'float', 'idouble',
51 'ifloat', 'ildouble', 'ldouble');
52
53 %beautify =
54 ( "minus_zero" => "-0",
55 "plus_zero" => "+0",
56 "minus_infty" => "-inf",
57 "plus_infty" => "inf",
58 "qnan_value" => "qNaN",
59 "M_El" => "e",
60 "M_E2l" => "e^2",
61 "M_E3l" => "e^3",
62 "M_LOG10El", "log10(e)",
63 "M_PIl" => "pi",
64 "M_PI_34l" => "3/4 pi",
65 "M_PI_2l" => "pi/2",
66 "M_PI_4l" => "pi/4",
67 "M_PI_6l" => "pi/6",
68 "M_PI_34_LOG10El" => "3/4 pi*log10(e)",
69 "M_PI_LOG10El" => "pi*log10(e)",
70 "M_PI2_LOG10El" => "pi/2*log10(e)",
71 "M_PI4_LOG10El" => "pi/4*log10(e)",
72 "M_LOG_SQRT_PIl" => "log(sqrt(pi))",
73 "M_LOG_2_SQRT_PIl" => "log(2*sqrt(pi))",
74 "M_2_SQRT_PIl" => "2 sqrt (pi)",
75 "M_SQRT_PIl" => "sqrt (pi)",
76 );
77
78
79 # get Options
80 # Options:
81 # u: ulps-file
82 # h: help
83 # o: output-directory
84 # n: generate new ulps file
85 use vars qw($opt_u $opt_h $opt_o $opt_n);
86 getopts('u:o:nh');
87
88 $ulps_file = 'libm-test-ulps';
89 $output_dir = '';
90
91 if ($opt_h) {
92 print "Usage: gen-libm-test.pl [OPTIONS]\n";
93 print " -h print this help, then exit\n";
94 print " -o DIR directory where generated files will be placed\n";
95 print " -n only generate sorted file NewUlps from libm-test-ulps\n";
96 print " -u FILE input file with ulps\n";
97 exit 0;
98 }
99
100 $ulps_file = $opt_u if ($opt_u);
101 $output_dir = $opt_o if ($opt_o);
102
103 $input = "libm-test.inc";
104 $output = "${output_dir}libm-test.c";
105
106 $count = 0;
107
108 &parse_ulps ($ulps_file);
109 &generate_testfile ($input, $output) unless ($opt_n);
110 &output_ulps ("${output_dir}libm-test-ulps.h", $ulps_file) unless ($opt_n);
111 &print_ulps_file ("${output_dir}NewUlps") if ($opt_n);
112
113 # Return a nicer representation
114 sub beautify {
115 my ($arg) = @_;
116 my ($tmp);
117
118 if (exists $beautify{$arg}) {
119 return $beautify{$arg};
120 }
121 if ($arg =~ /^-/) {
122 $tmp = $arg;
123 $tmp =~ s/^-//;
124 if (exists $beautify{$tmp}) {
125 return '-' . $beautify{$tmp};
126 }
127 }
128 if ($arg =~ /[0-9]L$/) {
129 $arg =~ s/L$//;
130 }
131 return $arg;
132 }
133
134 # Return a nicer representation of a complex number
135 sub build_complex_beautify {
136 my ($r, $i) = @_;
137 my ($str1, $str2);
138
139 $str1 = &beautify ($r);
140 $str2 = &beautify ($i);
141 if ($str2 =~ /^-/) {
142 $str2 =~ s/^-//;
143 $str1 .= ' - ' . $str2;
144 } else {
145 $str1 .= ' + ' . $str2;
146 }
147 $str1 .= ' i';
148 return $str1;
149 }
150
151 # Return name of a variable
152 sub get_variable {
153 my ($number) = @_;
154
155 return "x" if ($number == 1);
156 return "y" if ($number == 2);
157 return "z" if ($number == 3);
158 # return x1,x2,...
159 $number =-3;
160 return "x$number";
161 }
162
163 # Add a new test to internal data structures and fill in the
164 # ulps and exception information for the C line.
165 sub new_test {
166 my ($test, $exception, $show_exception) = @_;
167 my $rest;
168
169 # Add ulp.
170 if (exists $results{$test}{'has_ulps'}) {
171 $rest = ", DELTA$count";
172 } else {
173 $rest = ', 0';
174 }
175 if ($show_exception) {
176 if (defined $exception) {
177 $rest .= ", $exception";
178 } else {
179 $rest .= ', 0';
180 }
181 }
182 # We must increment here to keep @tests and count in sync
183 push @tests, $test;
184 ++$count;
185 return $rest;
186 }
187
188 # Adjust an argument or expected value for use in a constant
189 # initializer.
190 sub adjust_arg {
191 my ($arg, $in_func) = @_;
192 if (!$in_func) {
193 $arg =~ s/(plus_zero|minus_zero|plus_infty|minus_infty|qnan_value
194 |max_value|min_value|min_subnorm_value)/\U$1\E_INIT/xg;
195 }
196 return $arg;
197 }
198
199 # Treat some functions especially.
200 # Currently only sincos needs extra treatment.
201 sub special_functions {
202 my ($file, $in_func, $args) = @_;
203 my (@args, $str, $test, $cline);
204
205 @args = split /,\s*/, $args;
206
207 unless ($args[0] =~ /sincos/) {
208 die ("Don't know how to handle $args[0] extra.");
209 }
210 if ($in_func) {
211 $cline = " RUN_TEST_sincos (" . adjust_arg ($args[1], $in_func);
212 } else {
213 $cline = " { " . adjust_arg ($args[1], $in_func);
214 }
215
216 $str = 'sincos (' . &beautify ($args[1]) . ', &sin_res, &cos_res)';
217 # handle sin
218 $test = $str . ' puts ' . &beautify ($args[2]) . ' in sin_res';
219
220 my ($sin_res_var) = ($in_func ? ", sin_res" : "");
221 $cline .= ", \"$test\"$sin_res_var, " . adjust_arg ($args[2], $in_func);
222 $cline .= &new_test ($test, $args[4], 0);
223
224 # handle cos
225 $test = $str . ' puts ' . &beautify ($args[3]) . ' in cos_res';
226 my ($cos_res_var) = ($in_func ? ", cos_res" : "");
227 $cline .= ", \"$test\"$cos_res_var, " . adjust_arg ($args[3], $in_func);
228 $cline .= &new_test ($test, $args[4], 1);
229 if ($in_func) {
230 $cline .= ");\n";
231 } else {
232 $cline .= " },\n";
233 }
234 print $file $cline;
235 }
236
237 # Parse the arguments to TEST_x_y
238 sub parse_args {
239 my ($file, $descr, $fct, $in_func, $args) = @_;
240 my (@args, $str, $descr_args, $descr_res, @descr);
241 my ($current_arg, $cline, $i);
242 my (@special);
243 my ($extra_var, $call);
244
245 if ($descr eq 'extra') {
246 &special_functions ($file, $in_func, $args);
247 return;
248 }
249 ($descr_args, $descr_res) = split /_/,$descr, 2;
250
251 @args = split /,\s*/, $args;
252
253 $call = "$fct (";
254
255 # Generate first the string that's shown to the user
256 $current_arg = 1;
257 $extra_var = 0;
258 @descr = split //,$descr_args;
259 for ($i = 0; $i <= $#descr; $i++) {
260 if ($i >= 1) {
261 $call .= ', ';
262 }
263 # FLOAT, int, long int, long long int
264 if ($descr[$i] =~ /f|i|l|L/) {
265 $call .= &beautify ($args[$current_arg]);
266 ++$current_arg;
267 next;
268 }
269 # &FLOAT, &int - argument is added here
270 if ($descr[$i] =~ /F|I/) {
271 ++$extra_var;
272 $call .= '&' . &get_variable ($extra_var);
273 next;
274 }
275 # complex
276 if ($descr[$i] eq 'c') {
277 $call .= &build_complex_beautify ($args[$current_arg], $args[$current_arg+1]);
278 $current_arg += 2;
279 next;
280 }
281
282 die ("$descr[$i] is unknown");
283 }
284 $call .= ')';
285 $str = "$call == ";
286
287 # Result
288 @descr = split //,$descr_res;
289 foreach (@descr) {
290 if ($_ =~ /f|i|l|L/) {
291 $str .= &beautify ($args[$current_arg]);
292 ++$current_arg;
293 } elsif ($_ eq 'c') {
294 $str .= &build_complex_beautify ($args[$current_arg], $args[$current_arg+1]);
295 $current_arg += 2;
296 } elsif ($_ eq 'b') {
297 # boolean
298 $str .= ($args[$current_arg] == 0) ? "false" : "true";
299 ++$current_arg;
300 } elsif ($_ eq '1') {
301 ++$current_arg;
302 } else {
303 die ("$_ is unknown");
304 }
305 }
306 # consistency check
307 if ($current_arg == $#args) {
308 die ("wrong number of arguments")
309 unless ($args[$current_arg] =~ /EXCEPTION|ERRNO|IGNORE_ZERO_INF_SIGN/);
310 } elsif ($current_arg < $#args) {
311 die ("wrong number of arguments");
312 } elsif ($current_arg > ($#args+1)) {
313 die ("wrong number of arguments");
314 }
315
316
317 # Put the C program line together
318 # Reset some variables to start again
319 $current_arg = 1;
320 $extra_var = 0;
321 if ($in_func) {
322 $cline = "RUN_TEST_$descr";
323 } else {
324 $cline = "{ ";
325 }
326 # Special handling for some macros:
327 if ($in_func && $args[0] =~ /fpclassify|isnormal|isfinite|isinf|isnan
328 |issignaling|signbit|isgreater|isgreaterequal|isless|islessequal
329 |islessgreater|isunordered/x) {
330 $cline = "${cline}_tg";
331 }
332 if ($in_func) {
333 $cline .= " (";
334 }
335 $cline .= "\"$str\"";
336 if ($in_func) {
337 $cline .= ", $args[0]";
338 }
339 @descr = split //,$descr_args;
340 for ($i=0; $i <= $#descr; $i++) {
341 # FLOAT, int, long int, long long int
342 if ($descr[$i] =~ /f|i|l|L/) {
343 $cline .= ", " . adjust_arg ($args[$current_arg], $in_func);
344 $current_arg++;
345 next;
346 }
347 # &FLOAT, &int
348 if ($descr[$i] =~ /F|I/) {
349 next;
350 }
351 # complex
352 if ($descr[$i] eq 'c') {
353 $cline .= ", " . adjust_arg ($args[$current_arg], $in_func);
354 $cline .= ", " . adjust_arg ($args[$current_arg+1], $in_func);
355 $current_arg += 2;
356 next;
357 }
358 }
359 $cline .= ", ";
360
361 @descr = split //,$descr_res;
362 foreach (@descr) {
363 if ($_ =~ /b|f|i|l|L/ ) {
364 $cline .= adjust_arg ($args[$current_arg], $in_func);
365 $current_arg++;
366 } elsif ($_ eq 'c') {
367 $cline .= adjust_arg ($args[$current_arg], $in_func);
368 $cline .= ", " . adjust_arg ($args[$current_arg+1], $in_func);
369 $current_arg += 2;
370 } elsif ($_ eq '1') {
371 push @special, $args[$current_arg];
372 ++$current_arg;
373 }
374 }
375 # Add ulp.
376 $cline .= &new_test ($str, ($current_arg <= $#args) ? $args[$current_arg] : undef, 1);
377
378 # special treatment for some functions
379 if ($args[0] eq 'frexp') {
380 if (defined $special[0]) {
381 my ($extra_expected) = $special[0];
382 my ($run_extra) = ($extra_expected ne "IGNORE" ? 1 : 0);
383 my ($str) = "$call sets x to $extra_expected";
384 my ($out_var) = ($in_func ? ", x" : "");
385 if (!$run_extra) {
386 $str = "";
387 $extra_expected = "0";
388 }
389 $cline .= ", \"$str\"$out_var, 123456789, $run_extra, $extra_expected";
390 if ($run_extra) {
391 $cline .= &new_test ($str, undef, 0);
392 } else {
393 $cline .= ", 0";
394 }
395 }
396 } elsif ($args[0] eq 'gamma' || $args[0] eq 'lgamma') {
397 if (defined $special[0]) {
398 my ($extra_expected) = $special[0];
399 my ($run_extra) = ($extra_expected ne "IGNORE" ? 1 : 0);
400 my ($str) = "$call sets signgam to $extra_expected";
401 my ($out_var) = ($in_func ? ", signgam" : "");
402 if (!$run_extra) {
403 $str = "";
404 $extra_expected = "0";
405 }
406 $cline .= ", \"$str\"$out_var, 0, $run_extra, $extra_expected";
407 if ($run_extra) {
408 $cline .= &new_test ($str, undef, 0);
409 } else {
410 $cline .= ", 0";
411 }
412 }
413 } elsif ($args[0] eq 'modf') {
414 if (defined $special[0]) {
415 my ($extra_expected) = $special[0];
416 my ($run_extra) = ($extra_expected ne "IGNORE" ? 1 : 0);
417 my ($str) = "$call sets x to $extra_expected";
418 my ($out_var) = ($in_func ? ", x" : "");
419 if (!$run_extra) {
420 $str = "";
421 $extra_expected = "0";
422 }
423 $extra_expected = adjust_arg ($extra_expected, $in_func);
424 $cline .= ", \"$str\"$out_var, 123.456789, $run_extra, $extra_expected";
425 if ($run_extra) {
426 $cline .= &new_test ($str, undef, 0);
427 } else {
428 $cline .= ", 0";
429 }
430 }
431 } elsif ($args[0] eq 'remquo') {
432 if (defined $special[0]) {
433 my ($extra_expected) = $special[0];
434 my ($run_extra) = ($extra_expected ne "IGNORE" ? 1 : 0);
435 my ($str) = "$call sets x to $extra_expected";
436 my ($out_var) = ($in_func ? ", x" : "");
437 if (!$run_extra) {
438 $str = "";
439 $extra_expected = "0";
440 }
441 $cline .= ", \"$str\"$out_var, 123456789, $run_extra, $extra_expected";
442 if ($run_extra) {
443 $cline .= &new_test ($str, undef, 0);
444 } else {
445 $cline .= ", 0";
446 }
447 }
448 }
449 if ($in_func) {
450 print $file " $cline);\n";
451 } else {
452 print $file " $cline },\n";
453 }
454 }
455
456 # Generate libm-test.c
457 sub generate_testfile {
458 my ($input, $output) = @_;
459 my ($lasttext);
460 my (@args, $i, $str, $thisfct, $in_func);
461
462 open INPUT, $input or die ("Can't open $input: $!");
463 open OUTPUT, ">$output" or die ("Can't open $output: $!");
464
465 # Replace the special macros
466 $in_func = 0;
467 while (<INPUT>) {
468
469 # TEST_...
470 if (/^\s*TEST_/) {
471 my ($descr, $args);
472 chop;
473 ($descr, $args) = ($_ =~ /TEST_(\w+)\s*\((.*)\)/);
474 &parse_args (\*OUTPUT, $descr, $thisfct, $in_func, $args);
475 next;
476 }
477 # START_DATA (function)
478 if (/START_DATA/) {
479 ($thisfct) = ($_ =~ /START_DATA\s*\((.*)\)/);
480 $in_func = 0;
481 next;
482 }
483 # START (function)
484 if (/START/) {
485 ($thisfct) = ($_ =~ /START\s*\((.*)\)/);
486 $in_func = 1;
487 print OUTPUT " init_max_error ();\n";
488 next;
489 }
490 # END_DATA (function)
491 if (/END_DATA/) {
492 next;
493 }
494 # END (function)
495 if (/END/) {
496 my ($fct, $line, $type);
497 $in_func = 0;
498 if (/complex/) {
499 s/,\s*complex\s*//;
500 $type = 'complex';
501 } else {
502 $type = 'normal';
503 }
504 ($fct) = ($_ =~ /END\s*\((.*)\)/);
505 if ($type eq 'complex') {
506 $line = " print_complex_max_error (\"$fct\", ";
507 } else {
508 $line = " print_max_error (\"$fct\", ";
509 }
510 if (exists $results{$fct}{'has_ulps'}) {
511 $line .= "DELTA$fct";
512 } else {
513 $line .= '0';
514 }
515 $line .= ");\n";
516 print OUTPUT $line;
517 push @functions, $fct;
518 next;
519 }
520 print OUTPUT;
521 }
522 close INPUT;
523 close OUTPUT;
524 }
525
526
527
528 # Parse ulps file
529 sub parse_ulps {
530 my ($file) = @_;
531 my ($test, $type, $float, $eps, $kind);
532
533 # $type has the following values:
534 # "normal": No complex variable
535 # "real": Real part of complex result
536 # "imag": Imaginary part of complex result
537 open ULP, $file or die ("Can't open $file: $!");
538 while (<ULP>) {
539 chop;
540 # ignore comments and empty lines
541 next if /^#/;
542 next if /^\s*$/;
543 if (/^Test/) {
544 if (/Real part of:/) {
545 s/Real part of: //;
546 $type = 'real';
547 } elsif (/Imaginary part of:/) {
548 s/Imaginary part of: //;
549 $type = 'imag';
550 } else {
551 $type = 'normal';
552 }
553 s/^.+\"(.*)\".*$/$1/;
554 $test = $_;
555 $kind = 'test';
556 next;
557 }
558 if (/^Function: /) {
559 if (/Real part of/) {
560 s/Real part of //;
561 $type = 'real';
562 } elsif (/Imaginary part of/) {
563 s/Imaginary part of //;
564 $type = 'imag';
565 } else {
566 $type = 'normal';
567 }
568 ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
569 $kind = 'fct';
570 next;
571 }
572 if (/^i?(float|double|ldouble):/) {
573 ($float, $eps) = split /\s*:\s*/,$_,2;
574
575 if ($eps eq "0") {
576 # ignore
577 next;
578 } else {
579 $results{$test}{$type}{'ulp'}{$float} = $eps;
580 $results{$test}{'has_ulps'} = 1;
581 }
582 if ($type =~ /^real|imag$/) {
583 $results{$test}{'type'} = 'complex';
584 } elsif ($type eq 'normal') {
585 $results{$test}{'type'} = 'normal';
586 }
587 $results{$test}{'kind'} = $kind;
588 next;
589 }
590 print "Skipping unknown entry: `$_'\n";
591 }
592 close ULP;
593 }
594
595
596 # Clean up a floating point number
597 sub clean_up_number {
598 my ($number) = @_;
599
600 # Remove trailing zeros after the decimal point
601 if ($number =~ /\./) {
602 $number =~ s/0+$//;
603 $number =~ s/\.$//;
604 }
605 return $number;
606 }
607
608 # Output a file which can be read in as ulps file.
609 sub print_ulps_file {
610 my ($file) = @_;
611 my ($test, $type, $float, $eps, $fct, $last_fct);
612
613 $last_fct = '';
614 open NEWULP, ">$file" or die ("Can't open $file: $!");
615 print NEWULP "# Begin of automatic generation\n";
616 # first the function calls
617 foreach $test (sort keys %results) {
618 next if ($results{$test}{'kind'} ne 'test');
619 foreach $type ('real', 'imag', 'normal') {
620 if (exists $results{$test}{$type}) {
621 if (defined $results{$test}) {
622 ($fct) = ($test =~ /^(\w+)\s/);
623 if ($fct ne $last_fct) {
624 $last_fct = $fct;
625 print NEWULP "\n# $fct\n";
626 }
627 }
628 if ($type eq 'normal') {
629 print NEWULP "Test \"$test\":\n";
630 } elsif ($type eq 'real') {
631 print NEWULP "Test \"Real part of: $test\":\n";
632 } elsif ($type eq 'imag') {
633 print NEWULP "Test \"Imaginary part of: $test\":\n";
634 }
635 foreach $float (@all_floats) {
636 if (exists $results{$test}{$type}{'ulp'}{$float}) {
637 print NEWULP "$float: ",
638 &clean_up_number ($results{$test}{$type}{'ulp'}{$float}),
639 "\n";
640 }
641 }
642 }
643 }
644 }
645 print NEWULP "\n# Maximal error of functions:\n";
646
647 foreach $fct (sort keys %results) {
648 next if ($results{$fct}{'kind'} ne 'fct');
649 foreach $type ('real', 'imag', 'normal') {
650 if (exists $results{$fct}{$type}) {
651 if ($type eq 'normal') {
652 print NEWULP "Function: \"$fct\":\n";
653 } elsif ($type eq 'real') {
654 print NEWULP "Function: Real part of \"$fct\":\n";
655 } elsif ($type eq 'imag') {
656 print NEWULP "Function: Imaginary part of \"$fct\":\n";
657 }
658 foreach $float (@all_floats) {
659 if (exists $results{$fct}{$type}{'ulp'}{$float}) {
660 print NEWULP "$float: ",
661 &clean_up_number ($results{$fct}{$type}{'ulp'}{$float}),
662 "\n";
663 }
664 }
665 print NEWULP "\n";
666 }
667 }
668 }
669 print NEWULP "# end of automatic generation\n";
670 close NEWULP;
671 }
672
673 sub get_ulps {
674 my ($test, $type, $float) = @_;
675
676 if ($type eq 'complex') {
677 my ($res);
678 # Return 0 instead of BUILD_COMPLEX (0,0)
679 if (!exists $results{$test}{'real'}{'ulp'}{$float} &&
680 !exists $results{$test}{'imag'}{'ulp'}{$float}) {
681 return "0";
682 }
683 $res = 'BUILD_COMPLEX (';
684 $res .= (exists $results{$test}{'real'}{'ulp'}{$float}
685 ? $results{$test}{'real'}{'ulp'}{$float} : "0");
686 $res .= ', ';
687 $res .= (exists $results{$test}{'imag'}{'ulp'}{$float}
688 ? $results{$test}{'imag'}{'ulp'}{$float} : "0");
689 $res .= ')';
690 return $res;
691 }
692 return (exists $results{$test}{'normal'}{'ulp'}{$float}
693 ? $results{$test}{'normal'}{'ulp'}{$float} : "0");
694 }
695
696 # Output the defines for a single test
697 sub output_test {
698 my ($file, $test, $name) = @_;
699 my ($ldouble, $double, $float, $ildouble, $idouble, $ifloat);
700 my ($type);
701
702 # Do we have ulps?
703 if (!exists $results{$test}{'type'}) {
704 return;
705 }
706 $type = $results{$test}{'type'};
707 if (exists $results{$test}{'has_ulps'}) {
708 # XXX use all_floats (change order!)
709 $ldouble = &get_ulps ($test, $type, "ldouble");
710 $double = &get_ulps ($test, $type, "double");
711 $float = &get_ulps ($test, $type, "float");
712 $ildouble = &get_ulps ($test, $type, "ildouble");
713 $idouble = &get_ulps ($test, $type, "idouble");
714 $ifloat = &get_ulps ($test, $type, "ifloat");
715 print $file "#define DELTA$name CHOOSE($ldouble, $double, $float, $ildouble, $idouble, $ifloat)\t/* $test */\n";
716 }
717 }
718
719 # Print include file
720 sub output_ulps {
721 my ($file, $ulps_filename) = @_;
722 my ($i, $fct);
723
724 open ULP, ">$file" or die ("Can't open $file: $!");
725
726 print ULP "/* This file is automatically generated\n";
727 print ULP " from $ulps_filename with gen-libm-test.pl.\n";
728 print ULP " Don't change it - change instead the master files. */\n\n";
729
730 print ULP "\n/* Maximal error of functions. */\n";
731 foreach $fct (@functions) {
732 output_test (\*ULP, $fct, $fct);
733 }
734
735 print ULP "\n/* Error of single function calls. */\n";
736 for ($i = 0; $i < $count; $i++) {
737 output_test (\*ULP, $tests[$i], $i);
738 }
739 close ULP;
740 }
This page took 0.094088 seconds and 5 git commands to generate.