If i have a signed int 'val' and 'total' is an unsigned long and execute this in the arduino:
if (total - (val*4939)) {...}
What happens if val4939 is greater than 65536? Does it not matter because it's happening in the ALU not in the memory location?
Also what happens if the val4939 comes out negative but total is unsigned?
I'm not sure how I'm supposed to think about it.
The register being used to hold the result will overflow. You need to tell the compiler to use a larger register, by declaring val as long or appending UL to the constant so that the compiler knows to use a larger register.
Also what happens if the val*4939 comes out negative but total is unsigned?
Mixed mode comparisons are a disaster waiting to happen. Don't do it. Type or cast variables yourself so that you KNOW what will happen.
// Range LONG_LONG_MIN: -9223372036854775808
// Range LONG_LONG_MAX: 9223372036854775807
// Range ULONG_LONG_MAX: 18446744073709551615
// IMPORTANT NOTE - Assigning values requires suffix 'LL' for signed values and 'ULL' for unsigned values
long long n_max = 9223372036854775807LL;
long long n_min = -9223372036854775808LL;
unsigned long long n_umax = 18446744073709551615ULL;
Although there doesn't appear to be a wy for 'Serial.print' to display them.