[問題]應該算...FOR跟陣列的問題?
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEVC++,Matlab 2009a
問題(Question):
在C裡面可以將數字以每8Bits的長度存在一個陣列 例如 512*511*510=133432320
會存成 x[0]=33432320 x[1]=1,但轉成matlab後x(1,1)=33432320 x(1,2)卻沒有值過去
餵入的資料(Input):
C的部分:a=1,k=3,i=0,s=1,x[10000]={0},x[0]=1,carry=0,N=512
Matlab部分:k=3;N=512,carry=0,x=zeros(1,10000),x1=zeros(1,10000),x(1,1)=1,a=1:k
s=1
預期的正確結果(Expected Output):
x(1,1)=33432320,x(1,2)=1
錯誤結果(Wrong Output):
x(1,1)=33432320,x(1,2)=0
程式碼(Code):(請善用置底文網頁, 記得排版)
C:
for(a=1;a<=k;a++)
{
for(i=0;i<s;i++)
{
x[i]=x1[i]=x[i]*N+carry;
carry=x[i]/100000000;
x[i]=x1[i]=x[i]%100000000;
if(carry!=0 && i+1==s)
s++;
}
N-=1;
}
Matlab:
k=3;
N=512;
carry=0;
x=zeros(1,10000);
x1=zeros(1,10000);
s=1;
x(1,1)=1;
for a=1:k
for i=1:s
x(1,i)=x(1,i)*N+carry;
x1(1,i)=x(1,i)*N+carry;
carry=fix(x(1,i)/100000000);
x(1,i)=rem(x(1,i),100000000);
x1(1,i)=rem(x(1,i),100000000);
if (carry~=0 && i==s)
s=s+1;
end
N=N-1;
end
end
補充說明(Supplement):
想請問各位神手,我這樣照翻為何C與MATLAB的結果會不一樣QQ
我DEBUG好久了,所以上來求助各位神手,如果有發言不慎,還請各位見諒,謝謝:)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.133.200
推
04/22 01:06, , 1F
04/22 01:06, 1F
→
04/22 01:07, , 2F
04/22 01:07, 2F