[arm-gnu] an long long problem

Laurent Desnogues laurent.desnogues at gmail.com
Fri Mar 23 10:02:23 UTC 2012


On Thu, Mar 22, 2012 at 5:13 PM, zzzh.2007 <zzzh.2007 at qq.com> wrote:
> Hi, all,
>
> I am using sourcery_g++_lite_for_arm_eabi ( version of
> arm-2008q3-66-arm-none-eabi) in Contiki to do some programming, and below is
> my code that have problem:
>
> -----------------------------------------------
> short a,x;
> long long y;
>
> a = (short)rand();
> x = (short)rand() *10000/66536;
>
> y = a*x*x;

It's hard to say what you mean by wrong, but if you
really want a 64-bit product you'll have to cast at
least one of the terms.  For instance:

  y = (long long)a*x*x;


Laurent

> printf( "a and x are %d, %d \n", a, x);
> printf( " y is: %lld \n", y);
>
> ----------------------------------------------
> The problem is: the y result is always wrong.
>
> I have no idea why this is happening, any help?
>
> ________________________________
> Zhu
> 2012-03-22
>
> _______________________________________________
> arm-gnu mailing list
> arm-gnu at codesourcery.com
> http://sourcerytools.com/cgi-bin/mailman/listinfo/arm-gnu
>



More information about the arm-gnu mailing list