numeric operation with big numbers

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

numeric operation with big numbers

Post 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
Attachments
Captura.JPG
User avatar
Chris
Posts: 4725
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: numeric operation with big numbers

Post 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).
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply