On 2011-05-10, Miriam Dali <miriamd...@yahoo.fr> wrote:

> Thank you for your answer , I'm really sorry my question was not clear :(
> I wrote a simple code in C, but when I port it to mspgcc it doesn't give me 
> the right value. This is a part of my code:
> unsigned short int xk=3588, yk=47541, yk1, sig=10, de=1;
> unsigned long int xk1;
> xk1=( xk+(sig*(yk-xk)*de));
> yk1=xk1 % 65535;
>
> the result that I expect is xk1=443118 and yk1=49908, but in mspgcc it gives 
> me xk1=yk1=49902
> I don't know where is the fault may be in the type choice?

sig*(yk-xk)*de is too big to fit in 16 bits, so the result of that is
getting truncated, and which "wrong" answer you get will depend on the
order in which the mulitply operations are done.

You need to tell the compiler to calculate xk+(sig*(yk-xk)*de using
32-bit operations not 16-bit operations, so make one of the variables
on the right hand side (e.g. yk) a long integer.

-- 
Grant Edwards               grant.b.edwards        Yow! I want a WESSON OIL
                                  at               lease!!
                              gmail.com            


------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to