palindrome with numbers
#1
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&&))


[Image: math-tidbit-1.png]
Reply
#2
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.
Reply
#3
(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 Tongue ... It would be super cool to see a spreadsheet app in QB64!)
Reply
#4
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?


[Image: 2-Grosse-Zahlen.jpg]
Reply
#5
(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?


[Image: 2-Grosse-Zahlen.jpg]

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
Reply
#6
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.  Rolleyes

PS: These are tips that belong in a book about QB64.
Reply
#7
(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  Wink
Reply
#8
The Wiki is great! Really! But people like I need a book. A Wiki is a addition, but without book . . .
Reply




Users browsing this thread: 2 Guest(s)