Posts: 529
Threads: 67
Joined: Apr 2022
Reputation:
11
08-19-2022, 03:51 PM
(This post was last modified: 08-19-2022, 03:56 PM by madscijr.)
Here's a neat little math factoid a coworker shared with us,
if you multiply 111,111,111 times 111,111,111
the answer is 12345678987654321 (reads the same backwards as forwards).
I got it working in QB64 with _INTEGER64, but a plain Excel formula does not yield the right answer!
Code: (Select All) Dim n1&&, n2&&, n3&&, n4&&
n1&& = 111111111
n2&& = n1&& * n1&&
Print " " + _Trim$(Str$(n1&&))
Print " x " + _Trim$(Str$(n1&&))
Print " -----------------"
Print " = " + _Trim$(Str$(n2&&))
Print
n3&& = 12345678987654321
n4&& = Sqr(n3&&)
Print "Sqr(" + _Trim$(Str$(n3&&)) + ")"
Print " = " + _Trim$(Str$(n4&&))
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
08-19-2022, 03:57 PM
(This post was last modified: 08-19-2022, 04:02 PM by SMcNeill.)
Looks like Excel is probably converting to a DOUBLE type variable for the answer.
https://docs.microsoft.com/en-us/office/...d-by-excel -- from the online documentation, there's no INT64 type support. Since the result is larger than a LONG can hold, it's given as a DOUBLE, which loses precision after swapping into scientific notation.
Posts: 529
Threads: 67
Joined: Apr 2022
Reputation:
11
08-19-2022, 04:11 PM
(This post was last modified: 08-19-2022, 04:14 PM by madscijr.)
(08-19-2022, 03:57 PM)SMcNeill Wrote: Looks like Excel is probably converting to a DOUBLE type variable for the answer.
https://docs.microsoft.com/en-us/office/...d-by-excel -- from the online documentation, there's no INT64 type support. Since the result is larger than a LONG can hold, it's given as a DOUBLE, which loses precision after swapping into scientific notation.
Wow, I remember when Excel 2007 came out and everything started going to 64-bit, and we got a million rows and each cell could hold more than 255 characters. Sounds like they're due for another upgrade!
(I'm still a huge fan of Excel and VBA, which along with QB64 is my go-to programming and utility platform ... It would be super cool to see a spreadsheet app in QB64!)
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
I have a problem! It doesn't work at all with "111.111.111" (without points of course), but it gets interesting with 111.111: It is displayed correctly in VisualBasic 5.0, but not in QB64.
It doesn't matter if it's "Double", "_Integer64" or "_Unsigned _Integer64", the result is wrong.
Did I make a mistake there, or is that a bug?
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
08-19-2022, 09:02 PM
(This post was last modified: 08-19-2022, 09:04 PM by SMcNeill.)
(08-19-2022, 08:46 PM)Kernelpanic Wrote: I have a problem! It doesn't work at all with "111.111.111" (without points of course), but it gets interesting with 111.111: It is displayed correctly in VisualBasic 5.0, but not in QB64.
It doesn't matter if it's "Double", "_Integer64" or "_Unsigned _Integer64", the result is wrong.
Did I make a mistake there, or is that a bug?
Change it to:
DIM AS _INTEGER64 var1, var2, var3 (whatever the variable names were)
I refer you back to here: https://staging.qb64phoenix.com/showthread.php?tid=279
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
08-19-2022, 09:27 PM
(This post was last modified: 08-19-2022, 09:32 PM by Kernelpanic.)
Quote:Change it to:
DIM AS _INTEGER64 var1, var2, var3 (whatever the variable names were)
I refer you back to here: https://staging.qb64phoenix.com/showthread.php?tid=279
OK, now it works with 111.111.111 too. Thanks! --- Yes, this is like in C. Basic goes to C.
PS: These are tips that belong in a book about QB64.
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
(08-19-2022, 09:27 PM)Kernelpanic Wrote: Quote:Change it to:
DIM AS _INTEGER64 var1, var2, var3 (whatever the variable names were)
I refer you back to here: https://staging.qb64phoenix.com/showthread.php?tid=279
OK, now it works with 111.111.111 too. Thanks!
PS: These are tips that belong in a book about QB64.
Or maybe even in a wiki article: https://qb64phoenix.com/qb64wiki/index.php/DIM
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
The Wiki is great! Really! But people like I need a book. A Wiki is a addition, but without book . . .
|