The L suffix means long (32-bit), not long long (64-bit)
This works in Keil, other combinations result in ''integer operation result is out of range'' long long a = (long long)-1154800 * (long long)3289; Probably handled by the preprocessor, at the very least it should be folded by the optimizer. The LL suffix also works. long a = -1154800 * 3289; long long b = -1154800 * 3289; long long c = -1154800L * 3289L; long long d = (long long)-1154800 * (long long)3289; long long e = -1154800LL * 3289LL; printf(''a %ld\n'',a); printf(''b %lf\n'',(double)b); printf(''c %lf\n'',(double)c); printf(''d %lf\n'',(double)d); printf(''e %lf\n'',(double)e); a 496830096 b 496830096.000000 c 496830096.000000 d -3798137200.000000 e -3798137200.000000
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Now the calculation is correct too, when I just type in numbers. Though Ride7 and the RLINK debugger still shows the decimal representation wrong, as it can't show 64-bit numbers. But if I look in the RAM, the 8MSB's are F's - so the number is: 0xFFFFFFFF1D9D0690, which is correct.
Though if I just change my calibration matrix variables to long long, the code doesn't work at all, as the calculated x and y is over the screen limit - which shouldn't occour, but it occours on calculation errors.
The calibration matrix code and more can be seen here:
The analog readings go from 0 to 4096. The calibration code works fine on another screen with 320x240 resolution, but on the 800x480 resolution it doesn't work!
Ok, your POINT structure should use signed integers (int) as some of your computation generate negative numbers as POINT values are subtracted from each other, and unless casted will be handled as (unsigned int). This was specifically important with the computation of divisor when I tried casting to (double).
The coefficients seem to be correctly computed. In the computation of x and y, you need to use 64-bit temporary results, x and y can remain as 32-bit signed long. x = (((long long)matrix.An * xAnalogReading) + ((long long)matrix.Bn * yAnalogReading) + matrix.Cn) / matrix.Divider; y = (((long long)matrix.Dn * xAnalogReading) + ((long long)matrix.En * yAnalogReading) + matrix.Fn) / matrix.Divider;
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..