-2

I'm converting a pretty simple program I made in C code into Javascript. The code are identical, however I changed the code into Javascript syntax. For some reason my simple calculation in javascript language is giving me a different result than the one in C. Take a look below. I did some test to see if some of the variables values were the same. Everything, S, S1, S2, V1, V2, T4, LCP are the same. BUT T2 has a different value.

S = lesserofcalc(S1,S2);
alert("S1--->" + S1);
alert("S2--->" + S2);
alert("S--->" + S);
//printf("S1:%.2lf | S2:%.2lf | S:%.2lf | T4:%.2lf | V1:%.2lf | K2P:%.2lf \n",S1,S2,S,T4,V1, K2P);
if (LCPK<=LCPRATE*YY){
    LCP = LCPK;
} else {
    LCP = LCPRATE*YY;
}

V2 = OHP();
V2 = roundFIX(V2);
alert("V1--->" + V1);
alert("V2--->" + V2);
alert("T4--->" + T4);
alert("LCP--->" + LCP);

T2 = T4+V1+V2-S-LCP; *GIVING DIFFERENT VALUE FROM C ????*
alert("T2--->" + T2);
T2 = roundFIX(T2);

C Program:

S = lesserofcalc(S1,S2);
printf("S1-----> %.2lf \n", S1);
printf("S2-----> %.2lf \n", S2);
printf("S-----> %.2lf \n", S);

//printf("S1:%.2lf | S2:%.2lf | S:%.2lf | T4:%.2lf | V1:%.2lf | K2P:%.2lf \n",S1,S2,S,T4,V1, K2P);
if (LCPK<=LCPRATE*YY){
    LCP = LCPK;
} else {
    LCP = LCPRATE*YY;
}

V2 = OHP();
V2 = roundFIX(V2);
printf("v1-----> %.2lf \n", V1);
printf("V2-----> %.2lf \n", V2);
printf("T4-----> %.2lf \n", T4);
printf("LCP-----> %.2lf \n", LCP);
T2 = T4+V1+V2-S-LCP;
printf("T2-----> %.2lf \n", T2);

T2 = roundFIX(T2);
4

1 回答 1

0

解决。问题..抱歉是一个毫无意义的问题.. C和javascript中的代码完全相同,我猜它们运行指令/函数的方式不同......或者不是......

于 2013-02-13T02:38:10.557 回答