1
QB64 Discussion / Calculation difference between QB64 64 and 32 bit versions
« on: September 30, 2021, 10:13:42 am »
Hi,
Writing a little epoch calculator, I ran into an issue which looked like rounding. However, the suspected part was a muliplication of huge numbers.
Inspired by this topic https://www.qb64.org/forum/index.php?topic=4210.0 "Possible error in INTEGER64 calculations", I changed a variable in the suspected calculation to _INTEGER64 and got it working.
When noticing that I still was in QB64-32 I switched to QB64-64 and recompiled. And there the bug was back. I got it woriking by DIMming all variables to _INTEGER64.
Output QB64-32:
Output QB64-64:
Removing the REMarks on all DIM lines makes QB64-64 print the same correct result as QB64-32.
When all DIM's are REMmed and only the output var tm_epoch is _INTEGER64, both compilers calculate the result wrong by 16.
Both QB64 32 and 64 bit are version 1.5.
Is this some magic, or reversed restrictictions making the smaller bit compiler run more accurate?
What are the common rules and best practices here?
Writing a little epoch calculator, I ran into an issue which looked like rounding. However, the suspected part was a muliplication of huge numbers.
Inspired by this topic https://www.qb64.org/forum/index.php?topic=4210.0 "Possible error in INTEGER64 calculations", I changed a variable in the suspected calculation to _INTEGER64 and got it working.
When noticing that I still was in QB64-32 I switched to QB64-64 and recompiled. And there the bug was back. I got it woriking by DIMming all variables to _INTEGER64.
Code: QB64: [Select]
- ' 2019:02:05 17:50:30
- tm$ = "1978:09:30 15:00:00"
- 'tm$ = "1970:01:02 00:00:00"
- 'DIM tm_sec AS _INTEGER64
- 'DIM tm_min AS _INTEGER64
- 'DIM tm_hour AS _INTEGER64
- 'DIM tm_day AS _INTEGER64
- 'DIM tm_month AS _INTEGER64
- 'DIM tm_yday AS _INTEGER64
- PRINT tm$
- PRINT tm_yday ' check: https://www.esrl.noaa.gov/gmd/grad/neubrew/Calendar.jsp?view=DOY&year=2021&col=4
- PRINT tm_epoch&& ' check: https://www.epochconverter.com/
- 'PRINT
- 'PRINT (tm_year - 70) * 31536000&& ' this is the bastard
- 'PRINT INT((tm_year - 69) / 4) * 86400
- 'PRINT INT((tm_year - 1) / 100)
- 'PRINT INT((tm_year + 299) / 400) * 86400
Output QB64-32:
Code: Text: [Select]
- 1978:09:30 15:00:00
- 273
- 276015600
Output QB64-64:
Code: Text: [Select]
- 1978:09:30 15:00:00
- 273
- 276015616
Removing the REMarks on all DIM lines makes QB64-64 print the same correct result as QB64-32.
When all DIM's are REMmed and only the output var tm_epoch is _INTEGER64, both compilers calculate the result wrong by 16.
Both QB64 32 and 64 bit are version 1.5.
Is this some magic, or reversed restrictictions making the smaller bit compiler run more accurate?
What are the common rules and best practices here?