The manual states that the Quad/Int64 range is -9.22x10^18...9.22x10^18. Which is odd to represent an integer type in exponential notation. According to that notation the range is -9,220,000,000,000,000,000...9,220,000,000,000,000,000. However, the manual also states that a Quad is 8-bytes in size so the range
should be -9,223,372,036,854,775,808...9,223,372,036,854,775,807. So I wrote the following simple program to see if this is indeed the case.
'thinBasic 1.11.6.0
Uses "File"
Dim x As Int64
Dim hFile As DWORD
hFile = File_Open("int64.dat", "binary", SizeOf(Int64))
x = 9223372036854775807
file_put(hFile, mkq$(x)) ' uh oh 9,223,372,036,854,775,800 is written to the file
file_put(hFile, mkq$(0))
x = x + 1 ' no overflow!
file_put(hFile, mkq$(x)) ' but 9,223,372,036,854,775,801 is written to the file instead
file_put(hFile, mkq$(0))
x = &h7FFFFFFFFFFFFFFF ' hex representation of 9,223,372,036,854,775,807
file_put(hFile, mkq$(x)) ' *NOW* 9,223,372,036,854,775,807 is written to the file
file_put(hFile, mkq$(0))
x = x + 1 ' overflow!
file_put(hFile, mkq$(x)) ' minimum negative value of a quad -9,223,372,036,854,775,808
file_close(hFile)
So my question as to the exact range of a Quad is confirmed as -9,223,372,036,854,775,808...9,223,372,036,854,775,807. This is good.
However, there seems to be some disturbing behavoir in the interpreter. Looking at the output file with a hex editor you can see that when x is assigned the value of 9,223,372,036,854,775,807 it is
not honored (9,223,372,036,854,775,800) but when x is assigned the same value in a different base (7FFFFFFFFFFFFFFF) it is? What's going on? And more importantly how do I know when the value of a variable will be honored or not? 'Dim x as Quad' is a contract and if 9,223,372,036,854,775,807 is a valid value for a Quad it shouldn't depend on whether it is assigned to a variable in base 10 or base Z.