For a forthcoming article in xDev I had to use the Mod function and came across an interesting problem:
From the Xojo documentation:
result = number1 Mod number2
The Mod operator divides number1 by number2 and returns the remainder as result. If either number1 or number2 is a floating-point type, it is first coerced to Int32. If either number1 or number2 is an Int64, then both values are promoted to Int64.
What happens with result = doubleValue mod intValue?
result and intValue are Integer, and should be a 64 bit integer on a 64 bit system. Testing revealed that the coercing to 32bit Integer rule takes precedence over promoting to 64bit Integer on the right side.
But why would the double be coerced into a 32bit integer on 64 bit systems? That just screams overflow error! Have Xojo forgotten to update this when they moved to 64 bit?
Basically you are running into 32 bit limitations on a 64 bit system.
Christian dug out the over 10 year old bug report turned feature request 11536 - mod fails for doubles with divisors greater than [ ( 2 ^ 31 ) - 2 ] by Kem Tekinay that has been stuck in “reviewed” for over 10 years. It concludes “Please change this to a feature request for mod to coerce the values to Int64 instead.”
But it is MUCH worse than that: the same seems to apply to a number of other Math functions - it seems the underlying structure never got updated to 64 bit, and therefore with larger numbers you run into 32 bit limitations because of a systematic problems in Xojo.
The biggest problem is that your code might seem to work just fine - until it hits a not very large number that Int64 should easily handle and instead it fails. Which it would not if Xojo used Int64 on 64bit systems instead of coercing to Int32…
And now Xojo don’t seem to have a compiler guy anymore to fix it?
What kind of programming language has a systematic Maths error like this?