3 # This script processes the test cases from crlibm, see
4 # http://lipforge.ens-lyon.fr/www/crlibm/download.html
9 die "$0: missing crlibm directory\n" unless (defined $dir) && -d
$dir;
27 ['pow' => 'power', sub { $_[0] == 0 && $_[1] == 0; }],
35 # -----------------------------------------------------------------------------
41 my ($gfunc,$expr,$res) = @_;
43 my $gfunc0 = ($gfunc eq $last_func) ?
'' : $gfunc;
46 $res = "=$res" if $res =~ /[*^]/;
48 my $N = 1 + @test_lines;
49 push @test_lines, "\"$gfunc0\",\"$expr\",\"$res\",\"=IF(B$N=C$N,\"\"\"\",IF(C$N=0,-LOG10(ABS(B$N)),-LOG10(ABS((B$N-C$N)/C$N))))\"";
54 # -----------------------------------------------------------------------------
59 # 'd' here is native double layout. Sorry about that.
60 my $d = unpack ('d', pack ('VV', hex $l, hex $h));
65 if ($ad == 0 || ($ad > 1e-5 && $ad < 1e10
)) {
66 $s = sprintf ("%.99f", $d);
67 } elsif ($ad < 1e-300) {
68 my $l2 = int (log ($ad) / log (2));
69 $s = sprintf ("%.99f*2^%d", $d * 2 ** -$l2, $l2);
71 $s =sprintf ("%.99e", $d);
74 $s =~ s/(\.\d*[1-9])0+($|\D)/$1$2/;
75 $s =~ s/(\d)\.0+($|\D)/$1$2/;
77 #print STDERR "[$h] [$l] [$s]\n";
79 $s = undef if $s =~/nan|inf/i;
84 # -----------------------------------------------------------------------------
86 push @test_lines, ("") x
(10 + @funcs);
90 my ($func,$gfunc,$filter);
93 ($func,$gfunc,$filter) = @
$_;
98 print STDERR
"Processing data for $gfunc...\n";
100 my $first_row = 1 + @test_lines;
102 my $fn = "$dir/tests/$func.testdata";
105 die "$0: cannot read $fn: $!\n" unless open $src, "<", $fn;
107 # Skip header than mentions function name
109 last if /^\s*[a-z]/i;
117 my ($round, @d) = split (" ");
119 # Ignore everything except round-to-nearest
120 next unless $round eq 'N';
122 die "$0: Crazy line [$_]\n" unless @d >= 4 && (@d &1) == 0;
126 for (my $i = 0; $i < @d; $i += 2) {
129 my $x = &interpret_hex
($h, $l);
130 $bad = 1 unless defined $x;
137 next if $filter && &$filter (@data);
139 &output_test
($gfunc,
140 "$gfunc(".join(',', @data).")",
144 my $last_row = @test_lines;
145 if ($last_row >= $first_row) {
146 my $count = $last_row - $first_row + 1;
147 $test_lines[$func_no + 2] =
148 "$gfunc,$count,\"=min(D${first_row}:D${last_row},99)\"";
154 my $r1 = $func_no + 2;
155 $test_lines[0] = "\"Function\",\"Number of Tests\",\"Accuracy\",\"=min(C${r0}:C${r1})\"";
159 foreach (@test_lines) {
163 # -----------------------------------------------------------------------------