Commit b5b0a9cb authored by Yannick Ulrich's avatar Yannick Ulrich

configure: Made GiNaC test more useful

parent 3c1174c6
......@@ -591,12 +591,51 @@ if $HAVE_GINAC ; then
tee $test.ginac.cpp << _EOF_ 1>&2
#include <ginac/ginac.h>
#include <iostream>
int main() {
#include <cln/cln.h>
typedef struct {double r,i;} complex_t;
typedef struct {complex_t c; signed char i0;} inum_t;
complex_t geval_(inum_t * z, int* n) {
cln::cl_inhibit_floating_point_underflow = true;
GiNaC::lst w,s;
for(long i=0;i<(*n)-1;i++)
{
GiNaC::ex zz;
if (abs(z->c.i) < 1e-15)
w.append((z->c.r));
else
w.append((z->c.r)+(z->c.i)*GiNaC::I);
s.append(z->i0);
z++;
}
GiNaC::ex ans = GiNaC::G(w,s,z->c.r).evalf();
return {
.r = GiNaC::ex_to<GiNaC::numeric>(GiNaC::evalf(GiNaC::real_part(ans))).to_double(),
.i = GiNaC::ex_to<GiNaC::numeric>(GiNaC::evalf(GiNaC::imag_part(ans))).to_double()
};
}
int main() {
// Test 1
GiNaC::ex ans = GiNaC::G(0.3,0.5,0.7);
ans -= 0.2876820724517808812+3.1415926535897932385*GiNaC::I;
ans = GiNaC::abs(ans);
if (ans<1e-15)
// Test 2
inum_t x[] = {
{ .c = {.r = 0.73, .i=0}, .i0 = -1 },
{ .c = {.r = 0.00, .i=0}, .i0 = +1 },
{ .c = {.r = 1.00, .i=0}, .i0 = +1 }
};
int n=3;
complex_t cans = geval_(&x[0],&n);
float del = (2.2982889094420660-cans.r)*(2.2982889094420660-cans.r) + (0.98869296399417417-cans.i)*(0.98869296399417417-cans.i);
if ( (ans<1e-15) && (del<1e-15) )
return 0;
else
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment