1 ########################################################################
3 # This software is part of the ast package #
4 # Copyright (c) 1982-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
13 # Information and Software Systems Research #
17 # David Korn <dgk@research.att.com> #
19 ########################################################################
20 : generate the ksh math
builtin table
23 # @(#)math.sh (AT&T Research) 2009-08-18
27 iffehdrs
="math.h ieeefp.h"
40 eval `iffe $iffeflags -c "$cc" - typ long.double 2>&$stderr`
42 : check ast_standards.h
44 eval `iffe $iffeflags -F ast_standards.h -c "$cc" - tst use_ast_standards -lm 'note{' 'math.h needs ast_standards.h' '}end' 'link{' '#include <math.h>' '#ifndef isgreater' '#define isgreater(a,b) 0' '#endif' 'int main() { return isgreater(0.0,1.0); }' '}end'`
45 case $_use_ast_standards in
46 1) iffeflags
="$iffeflags -F ast_standards.h" ;;
52 while read type args name aka comment
54 [fi]) names
="$names $name"
56 case $_typ_long_double in
57 1) tests
="$tests,${name}l" ;;
59 eval TYPE_
$name=$type ARGS_
$name=$args AKA_
$name=$aka
64 : check the math library
66 eval `iffe $iffeflags -c "$cc" - lib $tests $iffehdrs $iffelibs 2>&$stderr`
69 do eval x
='$'_lib_
${name}l y
='$'_lib_
${name}
71 1) lib
="$lib,${name}l" ;;
75 '') lib
="$lib,${name}" ;;
80 eval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr`
85 /* : : generated by
$command from
$table : : */
87 typedef Sfdouble_t
(*Math_f
)(Sfdouble_t
,...
);
90 case $_use_ast_standards in
91 1) echo "#include <ast_standards.h>" ;;
93 echo "#include <math.h>"
95 1) echo "#include <ieeefp.h>" ;;
99 : generate the intercept functions and table entries
106 do eval x
='$'_lib_
${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name}
114 local=$_typ_long_double
119 eval x
='$'_lib_
${f}l y
='$'_lib_
${f}
127 L
=local_
$name r
=int R
=1
128 echo "#ifdef $v${nl}static $r $L(Sfdouble_t x) { return $f(x) == $v; }${nl}#endif"
129 tab
="$tab$nl#ifdef $v$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)${L},${nl}#endif"
135 eval n
='$'_npt_
$f m
='$'_mac_
$f d
='$'_dat_
$f
137 i
) L
=int r
=int R
=1 ;;
138 *) L
=Sfdouble_t r
=$t R
=0 ;;
143 *:*:1) code
="extern $r $f("
145 for p
in 1 2 3 4 5 6 7
146 do code
="$code${sep}$t"
156 case $local:$m:$n:$d in
157 1:*:*:*|
*:1:*:*|
*:*:1:)
159 code
="static $L local_$f("
161 for p
in 1 2 3 4 5 6 7 8 9
162 do args
="$args${sep}a$p"
163 code
="$code${sep}Sfdouble_t a$p"
169 code
="$code){return $f($args);}"
175 do tab
="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f,"
178 tab
="$tab$nl$ht\"\",$ht$ht(Math_f)0"
183 * first byte is two-digit octal number. Last digit is number of args
184 * first digit is
0 if return value is double
, 1 for integer
186 const struct mathtab shtab_math
[] =