Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponent computation bug #1741

Closed
fafalone opened this issue Dec 26, 2023 · 4 comments
Closed

Exponent computation bug #1741

fafalone opened this issue Dec 26, 2023 · 4 comments
Labels
bug Something isn't working parser

Comments

@fafalone
Copy link
Collaborator

Describe the bug
Thought I'd offer a more detailed analysis of the exponent bug reported by Ever on Discord. There's very serious issues with computing exponents in a fairly normal circumstance.

VB6
0 ^ (1 - 1) = 1
0 ^ (2 - 1) = 0
0 ^ (3 - 1) = 0
1 ^ (1 - 1) = 1
1 ^ (2 - 1) = 1
1 ^ (3 - 1) = 1
2 ^ (1 - 1) = 1
2 ^ (2 - 1) = 2
2 ^ (3 - 1) = 4
3 ^ (1 - 1) = 1
3 ^ (2 - 1) = 3
3 ^ (3 - 1) = 9
4 ^ (1 - 1) = 1
4 ^ (2 - 1) = 4
4 ^ (3 - 1) = 16
5 ^ (1 - 1) = 1
5 ^ (2 - 1) = 5
5 ^ (3 - 1) = 25
twinBASIC
0 ^ (1 - 1) = 1
0 ^ (2 - 1) = 1
0 ^ (3 - 1) = 1
1 ^ (1 - 1) = 0
1 ^ (2 - 1) = 1
1 ^ (3 - 1) = 2
2 ^ (1 - 1) = 0
2 ^ (2 - 1) = 1
2 ^ (3 - 1) = 4
3 ^ (1 - 1) = 0
3 ^ (2 - 1) = 1
3 ^ (3 - 1) = 8
4 ^ (1 - 1) = 0
4 ^ (2 - 1) = 1
4 ^ (3 - 1) = 16
5 ^ (1 - 1) = 0
5 ^ (2 - 1) = 1
5 ^ (3 - 1) = 32

VB gives the expected values, but tB values make no sense at all. 3^2 = 8, 4^=16, 5^2 = 32?? Ever suggest parsing was reversed; but that doesn't explain it either; 5^-2 is 0.04, not 32.

To Reproduce

Dim fizz As Long
Dim buzz As Long

Dim i As Long, j As Long
For i = 0 To 5
    For j = 1 To 3
        fizz = i: buzz = j
        Debug.Print i & " ^ (" & j & " - 1) = " & fizz ^ (buzz - 1)
    Next j
Next i

Expected behavior
Values should match VB6.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • twinBASIC compiler version 0.15.423

Additional context
Weird this bug has gone unnoticed until now.

@EduardoVB
Copy link

I think it is doing the opposite operation:
1^0 is doing 0^1 and 5^2 is doing 2^5

@fafalone
Copy link
Collaborator Author

Ah yes that kind of reversal explains it, good catch.

@fafalone fafalone added bug Something isn't working parser labels Dec 27, 2023
@fafalone
Copy link
Collaborator Author

Issue confirmed still present in 426.

@WaynePhillipsEA
Copy link
Collaborator

Fixed in BETA 427. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser
Projects
None yet
Development

No branches or pull requests

3 participants