xsharp.eu • numeric operation with big numbers
Page 1 of 1

numeric operation with big numbers

Posted: Thu Jul 25, 2024 9:02 pm
by jpmoschi
good afternoon guys

I'm coming back here after detecting an uncomfortable limit in VFP regarding very large numbers and I discover this.

A picture is worth a thousand words

xsharp last public version
visual studio 2019


Best regards
Juan

Re: numeric operation with big numbers

Posted: Thu Jul 25, 2024 9:49 pm
by Chris
Hi Juan,

This is because the result of the multiplication is too large to fit even in an Int64. The maximum positive value that can fit in the 64 bits of such a type is 9,223,372,036,854,775,807,as you can see with

? Int64.MaxValue:ToString()

Your test number of 123,456,789,012,345,678 is already very close to that and multiplying it by 100 makes it go beyond the limit and the result overflows. If you had enabled overflow checking in the project properties, a runtime overflow exception would be thrown.

If you need to use such very large numbers with precision, you can use directly the System.Decimal type, which uses 96 bits for representing a number, so can handle much larger ones than Int64 (but is also much slower).