Is it somehow possible to split the variables into 2 signed longs each, calculate them seperately, and then merge them back into a single signed long, after the calculation is done, and the value is small enough to be stored in a single signed long again?
Sure, though I can't see it being any faster . . .
Code:
type A, B;
/* ... */
signed long Ah = A >> 32, long Al = A & 0xffffff;
signed long Bh = B >> 32, long Bl = B & 0xffffff;
type C;
C = (type)(calculation);
You could use INT_MAX or whatever (from limits.h) rather than 0xffffff. I might have gotten the number of f's wrong . . .
The problem is, that C = (10000 * A) / B will give overflow, and that C = (A / B) / * 10000 is not accurate enough.
Here's what I might suggest.
Code:
C = (int)(10000 * ((double)A / B) + 0.5);
That way you get accurate values, including rounding, and no chance of overflow. However, it would be significantly slower since it involves floating-point calculations.
[edit] BTW, what type are A, B, and C? [/edit]