i have an R script that make some calculations.
and i found the same script but in C# , but it’s giving me answers different than R.
the R code is :
count=16569
for(ind1 in seq(1,count,by=1000))
{
for(ind2 in seq(1,count,by=1000))
{
value=(count*(ind1^2)) + ((count*(count+1)*((2*count)+1))/6) -(2*ind1*((count*(count+1))/2)) + (2*count*ind1*(count-ind2+1)) + ((count-ind2+1)*(count^2)) + (2*count*(ind2-count-1)*(ind2+count))
}
}
and the C# code is :
double count=16569
for(int ind1=1;ind1<=count;ind1+=1000)
{
for(int ind2=1;ind2<=count;ind2+=1000)
{
value=(count*(Math.Pow(ind1,2))) + ((count*(count+1)*((2*count)+1))/6) -(2*ind1*((count*(count+1))/2)) + (2*count*ind1*(count-ind2+1)) + ((count-ind2+1)*(Math.Pow(count,2))) + (2*count*(ind2-count-1)*(ind2+count))
}
}
for the first round , the value in R is : -3032615095125 but the value in C# is : 4548002182315
what is the error ?
thanks
I don’t know R, but with respect to C#, What datatype is the variable
value? Could it be that the values are overflowing and therefore junk?