The resultd1 value, as a double with at least one element as a clear double value forcing floating point calculations, is correct. I understand, I think, that the problems were caused by bit overflow since the correct result needs more than 32 bits. What surprised me, with my limited understanding of math internals, was that the UInt64 result was so weird. I apparently incorrectly assumed that it would be in line with the floating point calculation result. Silly me.
Interesting, in version 2020r2 on my Mac (10.15.17), it gives the answers I’d expect (15552000000 or 15552000000.00000, and resultiu1 still has the value 2667098112). But when I run it on Windows 10 (64 bit), I get the numbers you see.
I certainly wouldn’t expect different answers between Win and Mac.
You are right. Xojo doesn’t look what is left of the assignment here.
It will look on the constants. If they fit in int32, they will be int32 and so calculation is done in int32.
Ah, I forgot that was still an option for Windows. Changing it to 64 bit makes it match. It’s a little unintuitive to look there even when the build checkbox isn’t checked.
In further inspection looks like this is the normal compiler behavior. The compiler promotes values to that of the most precise type in the expression before doing a calculation without considering the Data Type where you are going to store the result.
So, another option to avoid doubles can be to use a Int64 in the expression:
Dim k As Int64 = 1000
Dim resultI64 As Int64
resultI64 = 24 * 60 * 60 * 180 * k
I went into more detail in my xDev article, and yes, also stated that it cannot be that you get different results on your Mac at home and your PC at work. Especially as you can use 64bit integers in 32bit Windows.
It’s really unexpected for people.
Maybe a feedback case could be made to have xojo compiler promote integers to 64-bit in 32-bit to make it perform like on a 64-bit CPU?
Understand that past can hurt, been there but why stop trying to help Xojo become better?
I mean for newbies and experienced because we will always encounter situations no matter how experienced we are in any language or stack