Wonderful help last night getting M_APM math library up for me. Thank you. I finished with the math later last night, but have a problem, that I couldn't get to go away all day: Anyone know of undocumented bugs in M_APM like this one?
If I remark out the m_apm_multiply() statement (marked in code with //====>) the loop runs with no problems, of course, providing an incorrect answer. With that multiply statement in, it sometimes freezes at run time, sometimes gives me a runtime error of "can't find "cpu_capabilities.h" file and sometimes another runtime error I can't remember or reproduce right now.
I tried both sprintf and m_apm_set_long to get int nnn into m_apm n to make sure that wasn't screwing things up.
By having each step report, I found that the multiply processes ok, and things progress to the next loop iteration. But it doesn't proceed. If I remark out the multiply, the loop proceeds just fine. Does a C++ while loop use a stack that m_apm could be messing up? I am just throwing out ideas.
Any ideas?
Jerry
If I remark out the m_apm_multiply() statement (marked in code with //====>) the loop runs with no problems, of course, providing an incorrect answer. With that multiply statement in, it sometimes freezes at run time, sometimes gives me a runtime error of "can't find "cpu_capabilities.h" file and sometimes another runtime error I can't remember or reproduce right now.
I tried both sprintf and m_apm_set_long to get int nnn into m_apm n to make sure that wasn't screwing things up.
By having each step report, I found that the multiply processes ok, and things progress to the next loop iteration. But it doesn't proceed. If I remark out the multiply, the loop proceeds just fine. Does a C++ while loop use a stack that m_apm could be messing up? I am just throwing out ideas.
Any ideas?
Jerry
Code:
M_APM p,L,n,iL,ct,cn,tr,a,b,c,d,p2;
int ll,nn,nnn;
p = m_apm_init();
... for each M_APM handles ...
m_apm_set_string(p,"2e21");
m_apm_set_string(L,"2e21");
...
// this formula is called the holy smokes!
// it is the chance (0-1) that
// p, L and n can have the given values
//
// p! /(p-n)! n! /L^n * (1-1/L)^(p-n)
//
// lets break it into two parts since we
// do not want to take the factorial of 2e21
// not even 32000 digits can do that
// a * b
// find a
// by sneaking around (p-n)! with a loop
a= MM_One;
p2= p;
nnn= nn;
while (nnn>=1){
// tried m_apm_set_long(n, nnn);
// both of sprintf(obuf, "%d", nnn);
// these m_apm_set_string(n, obuf);
m_apm_divide(tr, 400, a, n);
//=====> m_apm_multiply(a, tr, p2);
m_apm_divide(tr, 400, a, L);
a=tr;
m_apm_subtract(tr, p2, MM_One);
p2=tr;
nnn--;
}
// find b
m_apm_subtract(c, MM_One, iL);
m_apm_set_long(n, nn); // <==== set_long(int ) works fine here
m_apm_subtract(d, p, n);
m_apm_pow(b, 400, c, d);
// put it all together
m_apm_multiply(cn, a, b);
m_apm_add(tr, ct, cn);
ct=ct+tr;
m_apm_to_fixpt_string(obuf, 15, cn);
m_apm_to_fixpt_string(obuf2, 3, ct);
printf("\rn = %5i %s %s\n",nn, obuf, obuf2);