QB64 Phoenix Edition
Potencies high potencies - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Potencies high potencies (/showthread.php?tid=3107)



Potencies high potencies - Kernelpanic - 10-07-2024

When I wanted to try something today, I came across a problem, at least for me.
The results do not match what the MS calculator and online calculators give. I am also confused by the fact that ((5 ^ 4)^4) is not the same as 5^(4*4) for the program, but 5^16 gives a result like ((5 ^ 4)^4). Have I there disregarded some mathematical laws?  Huh

Code: (Select All)

'Matheuebung Potenzen hoch Potenzen - 7. Okt. 2024

Option _Explicit

Dim As Integer a, b, c
Dim As _Unsigned Long sum, sum2, sum3

Locate 2, 3
Print "Berechnet ((a ^ b) ^ c)"
Locate 3, 3
Print "======================="
'Beispiel: ((5^4)^4) = 5^16
'MS-Rechner: 152.587.890.625 -- Hier: 2.264.035.265

Locate 5, 3
Input "a: ", a
Locate 6, 3
Input "b: ", b
Locate 7, 3
Input "c: ", c

sum = ((a ^ b) ^ c)
Locate 9, 3
Print Using "Summe 1: ###,##########"; sum

sum2 = a ^ (a * b)
Locate 11, 3
Print Using "Summe 2: ###,##########"; sum2

sum3 = a ^ 16
Locate 13, 3
Print Using "Summe 3: ###,##########"; sum3

End

[Image: Matheuebung-Potenzen2.jpg]

Math-Solver


RE: Potencies high potencies - bplus - 10-07-2024

(10-07-2024, 09:21 PM)Kernelpanic Wrote: When I wanted to try something today, I came across a problem, at least for me.
The results do not match what the MS calculator and online calculators give. I am also confused by the fact that ((5 ^ 4)^4) is not the same as 5^(4*4) for the program, but 5^16 gives a result like ((5 ^ 4)^4). Have I there disregarded some mathematical laws?  Huh

Code: (Select All)

'Matheuebung Potenzen hoch Potenzen - 7. Okt. 2024

Option _Explicit

Dim As Integer a, b, c
Dim As _Unsigned Long sum, sum2, sum3

Locate 2, 3
Print "Berechnet ((a ^ b) ^ c)"
Locate 3, 3
Print "======================="
'Beispiel: ((5^4)^4) = 5^16
'MS-Rechner: 152.587.890.625 -- Hier: 2.264.035.265

Locate 5, 3
Input "a: ", a
Locate 6, 3
Input "b: ", b
Locate 7, 3
Input "c: ", c

sum = ((a ^ b) ^ c)
Locate 9, 3
Print Using "Summe 1: ###,##########"; sum

sum2 = a ^ (a * b)
Locate 11, 3
Print Using "Summe 2: ###,##########"; sum2

sum3 = a ^ 16
Locate 13, 3
Print Using "Summe 3: ###,##########"; sum3

End

[Image: Matheuebung-Potenzen2.jpg]

Math-Solver

4^4 is not 16

yeah so how you group them makes a difference
5^4 then ^4
is far less than
5 ^(4^4)


RE: Potencies high potencies - Kernelpanic - 10-07-2024

4^4 = 256, that's clear. But from what I've read, ((5^4)^4) should be equal to 5^(4*4). That's how the MS calculator shows it.
So that should be mathematically correct.


RE: Potencies high potencies - LEM - 10-07-2024

(10-07-2024, 10:20 PM)Kernelpanic Wrote: 4^4 = 256, that's clear. But from what I've read, ((5^4)^4) should be equal to 5^(4*4). That's how the MS calculator shows it.
So that should be mathematically correct.
You are correct that ((5^4)^4) is the same as 5^16.  I think your issue is dimensioning the "sum" variables as long (or unsigned long).  The result of 5^16 is much larger than can be represented by a long, I think.  Try without dimensioning as unsigned long.


RE: Potencies high potencies - Kernelpanic - 10-08-2024

Quote:@LEM -  I think your issue is dimensioning the "sum" variables as long (or unsigned long).  The result of 5^16 is much larger than can be represented by a long, I think.  Try without dimensioning as unsigned long.
Thanks, that was it! And a typo in sum 2 was the reason for the wrong result. Now it works.

Code: (Select All)

'Matheuebung Potenzen hoch Potenzen - 7./8. Okt. 2024

Option _Explicit

Dim As Integer a, b, c
Dim As _Integer64 sum, sum2, sum3

Locate 2, 3
Print "Berechnet ((a ^ b) ^ c)"
Locate 3, 3
Print "======================="
'Beispiel: ((5^4)^4) = 5^16
'MS-Rechner: 152.587.890.625 -- Hier: 2.264.035.265

Locate 5, 3
Input "a: ", a
Locate 6, 3
Input "b: ", b
Locate 7, 3
Input "c: ", c

sum = ((a ^ b) ^ c)
Locate 9, 3
Print Using "Summe 1: ###,############"; sum

sum2 = a ^ (c * b)
Locate 11, 3
Print Using "Summe 2: ###,############"; sum2

sum3 = a ^ 16
Locate 13, 3
Print Using "Summe 3: ###,############"; sum3

End

[Image: Matheuebung-Potenzen-Korr.jpg]