Hello, my name is John McPherson, and I write C code for the U.S. Department of Labor. I am in the process of converting C code for a lot states from a 32-bit system to a 64-bit system. Some states have been converted, and most have gone smoothly, but one state is having a major problem. I have isolated the problem to one paticular module, and the code of this module follows:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "maff.h"
#include "maffdef"
int i,j,k;
int creg_(int kky,int kkq)
{
/* this s/r determines the regular tax rate for each emp.*/
int ky, kq, ky1, kq1;
int icla = 0;
int goto70 = 0;
double ra1;
ky = kky;
kq = kkq;
ky1 = ky-1;
kq1 = kq-1;
printf("\n%25s\n"," TAX RATE CALCULATION");
//printf("%7s %6s %8s %8s %8s %10s\n","WUNENG","J","RAP","KTAB","ICLA","CONRM");
/* printf(">>>>>>>>>>>>>>>>>>The value of knri is %d\n", kri); */
if( kri-1<=0)
{
for(i=1;i<= ndis;i++) /*do 40 i=1, ndis*/
{
ra1 = rap[i-1];
if(ra1>=0.)
{
icla = ra1/ xprap+10./ xnrap+2.;
if (ra1 > 15.)
icla = 10./( xnrap+15.)/( xprap+2.) ;
}
else
{
icla = (ra1+10.)/ xnrap+2.;
if(ra1<-10.)
icla = 1;
}
/* printf("The value of icla is %d TTTTTTTTTT\n",icla); */
conrm[i-1] = xrate[icla-1][ ktab-1];
//aa[i-1] = xrate[icla-1][0];
printf("KRI,KY,CONRM,ICLA,KTAB,XRATE are %d %d %lf %d %d %lf\n", kri,ky,conrm[i-1],icla,ktab,xrate[icla-1][ktab-1]);
}
}
else /* kri-1 > 0 */
{
/* (variable rap intervals, kri=2) */
for(j=1;j<= ndis;j++)
{
conrm[j-1] = 0.0;
ra1 = rap[j-1];
ra1 = ra1/100.0;
for(i=1;i<= knri;i++)
{
if(ra1<0.0)
{
if(ra1 <= xrapi[i-1] + 0.0000001)
{
goto70 = 1;
printf("DEBUG: ra1 is %lf, xrapi is %lf\n", ra1, xrapi[i-1]);
break;
}
}
else
{
if(ra1 < xrapi[i-1])
{
goto70 = 1;
printf("DEBUG: ra1 is %lf, xrapi is %lf\n", ra1, xrapi[i-1]);
break;
}
}
}
if(!goto70)
{
i = knri+1;
printf("DEBUG: ra1 is %lf, xrapi is %lf, i is %d\n", ra1, xrapi[i-1], i);
}
icla = i;
goto70 = 0;
conrm[j-1] = xrate[icla-1][ktab-1];
/* printf("%7s %6d %10.4f %6d %6d %10.5f\n","WUNENG1", j,rap[j-1],ktab,icla,conrm[j-1]); */
conswm[j-1] = xtrigs[icla-1];
printf("KRI,KY,CONRM,ICLA,KTAB,XRATE are %d %d %lf %d %d %lf\n", kri,ky,conrm[i-1],icla,ktab,xrate[icla-1][ktab-1]);
}
}
return 0;
}
This code works for the first two years the module is called( this application pedicts the unemploymnet trust fund for the state in future years), but starting in the third year it is called, the 32-bit and 64-bit systems start getting different results. Below is the Debug listing for the 64-bit code in the third year:
TAX RATE CALCULATION
DEBUG: ra1 is 0.447402, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.364693, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.307749, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.276921, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.254421, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.239018, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.227467, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.218050, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.207246, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.204366, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.202762, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.197982, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.182876, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.186260, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.177461, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.184956, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.176551, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.167812, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 44 6 1.220000
DEBUG: ra1 is 0.168844, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 44 6 1.220000
DEBUG: ra1 is 0.173439, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.173427, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.174459, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.172511, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 45 6 1.070000
DEBUG: ra1 is 0.169946, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 44 6 1.220000
DEBUG: ra1 is 0.165021, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.830000 44 6 1.220000
This is only a partial debug listing, but it is enough to complare to the 32-bit debug listing below:
TAX RATE CALCULATION
DEBUG: ra1 is 0.449120, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.359665, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.300799, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.260753, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.227522, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.228402, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.214150, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.211497, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.196708, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.195283, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.183477, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.181437, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.181227, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.174001, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.178600, xrapi is 0.000000, i is 45
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 45 6 1.070000
DEBUG: ra1 is 0.119736, xrapi is 0.120000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 37 6 2.450000
DEBUG: ra1 is 0.156955, xrapi is 0.160000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 43 6 1.380000
DEBUG: ra1 is 0.166056, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
DEBUG: ra1 is 0.167515, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
DEBUG: ra1 is 0.163263, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
DEBUG: ra1 is 0.163469, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
DEBUG: ra1 is 0.160229, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
DEBUG: ra1 is 0.159966, xrapi is 0.160000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 1.040000 43 6 1.380000
DEBUG: ra1 is 0.160318, xrapi is 0.170000
KRI,KY,CONRM,ICLA,KTAB,XRATE are 2 4 0.940000 44 6 1.220000
The first issue is that on both the 32-bit and 64-bit systems, the simple assign of xrate to conrm does not seem to work, and it is a simple assignment statement. The code still seems to work on both systems, but they start producing different values, and with the assign statement acting strange on both, I don't know which to trust. I have reorganized memory on the 64-bit system, by reordering variable in the .h files, but it does not change anything. I solved a problem in another state by reorganizing memory, so that was one of my early attempts with this state. Note that all variables in this module are accounted for by .h declarations if they are not declared in this module, and the code compiles cleanly on both the 32-bit and 64-bit systems. Any help with this is greatly appreciated, and this is very strange problem.