Mulitplying Large Int64 numbers
When multiplying very large Int64 numbers, I've noticed some strange results.
For example, in C# .NET: Changing the multiplier to 4 as follows: Making the lngNumber slightly lower, gives a different effect. This correctly returns Has anyone any idea why this happens? Surely it would be better to return an exception like an overflow to a Byte or smaller integer does. I think that the Int64 struct should test the value being assigned to it, and reject it if it cannot handle it.
Int64 lngNumber;
lngNumber = 4611686018427387904;
lngNumber = lngNumber*2;
Console.WriteLine(lngNumber.ToString());
Outputs-9223372036854775808Changing the multiplier to 3 as follows:
Int64 lngNumber;
lngNumber = 4611686018427387904;
lngNumber = lngNumber*2;
Console.WriteLine(lngNumber.ToString());
Gives-4611686018427387904
lngNumber = 4611686018427387904;
lngNumber = lngNumber*4;
Console.WriteLine(lngNumber.ToString());
Outputs0(but no exception)
A valid calculation works fine:
Int64 lngNumber = 4611686018427387000;
lngNumber = lngNumber*2;
Console.WriteLine(lngNumber.ToString());
Whereas multiplying it by 3 returns -4611686018427390616.
Multiplying by 4 returns -3616.
By 5 returns 4611686018427383384.
By 6 returns 9223372036854770384.
By 7 returns -4611686018427394232.
By 8 returns -7232.
It seems to be looping round - once it reaches the maximum number allowed for an Int64, it keeps adding on at -9223372036854775808.
Is it an error?
I've been told that there is no exception raised for overflowing an integer in C, C++ and C#. Why not? And why would it return an incorrect value?

