]> www.ginac.de Git - ginac.git/commitdiff
genheader.pl: create a header file 'cint_workaround.h' to fix the broken
authorAlexander Frink <Alexander.Frink@uni-mainz.de>
Fri, 28 Jan 2000 18:26:41 +0000 (18:26 +0000)
committerAlexander Frink <Alexander.Frink@uni-mainz.de>
Fri, 28 Jan 2000 18:26:41 +0000 (18:26 +0000)
cint overloading for C math library functions

cint/configure
cint/genheader.pl [new file with mode: 0755]

index 0b3941f095cb3b984d7f0d90f2dc24a8aecd8cc8..ec988b42a1ca186cb6c0c8d86d15922e919d0420 100755 (executable)
@@ -29,7 +29,8 @@ echo "ok, cint seems to be in \$PATH"
 makecint -mk Makefile -o ginaccint -m \
  -D OBSCURE_CINT_HACK -D NO_GINAC_NAMESPACE \
  -I .. -I $CINTSYSDIR \
- -m -H ../ginac/ginac.h -C++ dummy_ginsh.cpp -C++ ginaccint.cpp \
+ -m -H ../ginac/ginac.h -H cint_workaround.h \
+ -C++ dummy_ginsh.cpp -C++ ginaccint.cpp \
  -l ../ginac/.libs/libginac.a -lcln \
  -cint -M0x10
 echo "ok, makecint has created the Makefile"
diff --git a/cint/genheader.pl b/cint/genheader.pl
new file mode 100755 (executable)
index 0000000..7c4a98f
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/perl -w
+
+# Generate a header file which is additionally included in cint
+# to work around the broken overloading resolution of cint for
+# C library functions
+# e.g. if a function declared as ex sin(ex const & x) and called
+# with sin(y) where y is a symbol, cint favours a conversion from
+# symbol to void * to double over symbol to ex and thus calls the
+# C math library function double sin(double x) (sigh!)
+
+$header='cint_workaround.h';
+
+# types which need help to be converted to ex
+@types=('symbol','function','constant','idx','lorentzidx','coloridx');
+@moretypes=('numeric','int','double');
+@extype=('ex');
+
+# functions with one parameter
+@functions1p=('sin','cos','tan','asin','acos','atan','exp','log','sqrt',
+              'sinh','cosh','tanh','abs');
+
+# functions with two parameters
+@functions2p=('pow','atan2');
+
+open OUT,">$header";
+
+foreach $f (@functions1p) {
+    print OUT "// fixes for $f(x)\n";
+    foreach $t (@types) {
+        print OUT "inline ex $f($t const & x) { return $f(ex(x)); }\n";
+    }
+    print OUT "\n";
+}  
+
+sub inlines2 {
+    my ($types1ref,$types2ref)=@_;
+    foreach $t1 (@$types1ref) {
+        foreach $t2 (@$types2ref) {
+            print OUT "inline ex $f($t1 const & x,$t2 const & y) {\n";
+            print OUT "    return $f(ex(x),ex(y));\n";
+            print OUT "}\n";
+        }
+    }
+}
+
+foreach $f (@functions2p) {
+    print OUT "// fixes for $f(x,y)\n";
+    inlines2(\@types,\@types);
+    inlines2(\@types,\@moretypes);
+    inlines2(\@moretypes,\@types);
+    inlines2(\@extype,\@moretypes);
+    inlines2(\@moretypes,\@extype);
+    print OUT "\n";
+}  
+
+close OUT;
+
+