Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Big numbers, strange errors

May
12,834
163
I have a @FACT plugin (factorial), essentially:
Code:
{
   ...
   Evaluate(psz);
   INT x = _wtoi(psz);
   while ( x > 1 )
   {
     Sprintf(psz+lstrlen(psz), L"*%d", (x -= 1));
     Evaluate(psz);
   }
   return 0;
}
It works fine up to %@FACT[3248] when he result (and Evaluate()'s argument) are just under 10000 characters (@eval's output limit for integers). So I limit @FACT to numbers <= 3248. That works fine.

I'm working on another plugin, @BINOM[n,k] (binomial coefficient, n!/(k!(n-k)!)). Right now,
Code:
INT WINAPI f_BINOM ( WCHAR *psz )
{
   DWORD n, k;
   if ( Sscanf(psz, L"%u,%u", &n, &k) != 2 || n > 3248 || k > n )
     return 0;
   Sprintf(psz, L"%%@FACT[%d] / %%@FACT[%d] / %%@FACT[%d]", n, k, n-k);
   ExpandVariables(psz, 0);
   Evaluate(psz);
   return 0;
}

If I try @BINOM[3200,1600] (about 1000 digits), it works. The expanded line passed to Evaluate() is about 18700 characters long and its first (and longest) token is about 9830 characters long. If I try it a second time, any of a variety of things may happen. One result (which I've never seen before) is:
Code:
v:\> echo %@binom[3200,1600]
MAPM Error: 'm_apm_to_fixpt_string', Out of memory
After that, a third try produces nothing
Code:
v:\> echo %@binom[3200,1600]
v:\>
And ~30 seconds later, TCC disappears.

I don't think I'm running into TCC's size limits. But I'd like to limit it to avoid errors.
Does anyone (Rex?) have an idea of what difficulty it's running into?
 

Similar threads

Back
Top