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