Modify

Opened 3 years ago

Closed 2 years ago

Last modified 18 months ago

#3869 closed Bug (Fixed)

Subtraction operator before power operation is parsed incorrectly

Reported by: AspirinJunkie Owned by: Jon
Milestone: 3.3.16.1 Component: AutoIt
Version: 3.3.16.0 Severity: None
Keywords: power minus Cc:

Description

For the operation of the basic form a - b^e, the result depends on the data type of the base b and the parity of the exponent e.

The following test script:

Global $sString = ""

$x = 2

$y = 4
$sString = StringFormat("% 15s = %d\n", "11 - 2 ^ 4", 11 - 2 ^ 4) & _
    StringFormat("% 15s = %d\n", "11 - 2.0 ^ 4", 11 - 2.0 ^ 4) & _
        StringFormat("% 15s = %d\n", "11 - 2e0 ^ 4", 11 - 2e0 ^ 4) & _
        StringFormat("% 15s = %d\n", "11 - '2' ^ 4", 11 - '2' ^ 4) & _
        StringFormat("% 15s = %d\n", "11 - $x ^ 4", 11 - $x ^ 4) & _
        StringFormat("% 15s = %d\n", "11 - (2 ^ 4)", 11 - (2 ^ 4)) & _
        StringFormat("% 15s = %d\n", "11 - - 2 ^ 4", 11 - - 2 ^ 4) & _
        StringFormat("% 15s = %d\n\n", "11 - 2 ^ $y", 11 - 2 ^ $y) 

$y = 3
$sString &= StringFormat("% 15s = %d\n", "11 - 2 ^ 3", 11 - 2 ^ 3) & _
    StringFormat("% 15s = %d\n", "11 - 2.0 ^ 3", 11 - 2.0 ^ 3) & _
        StringFormat("% 15s = %d\n", "11 - 2e0 ^ 3", 11 - 2e0 ^ 3) & _
        StringFormat("% 15s = %d\n", "11 - '2' ^ 3", 11 - '2' ^ 3) & _
        StringFormat("% 15s = %d\n", "11 - $x ^ 3", 11 - $x ^ 3) & _
        StringFormat("% 15s = %d\n", "11 - (2 ^ 3)", (11 - 2 ^ 3)) & _
        StringFormat("% 15s = %d\n", "11 - - 2 ^ 3", 11 - 2 ^ 3) & _
        StringFormat("% 15s = %d\n\n", "11 - 2 ^ $y", 11 - 2 ^ $y) 

ConsoleWrite($sString)

produces under 3.3.16.0:

     11 - 2 ^ 4 = 27
   11 - 2.0 ^ 4 = 27
   11 - 2e0 ^ 4 = 27
   11 - '2' ^ 4 = -5
    11 - $x ^ 4 = -5
   11 - (2 ^ 4) = -5
   11 - - 2 ^ 4 = -5
    11 - 2 ^ $y = 27

     11 - 2 ^ 3 = 3
   11 - 2.0 ^ 3 = 3
   11 - 2e0 ^ 3 = 3
   11 - '2' ^ 3 = 3
    11 - $x ^ 3 = 3
   11 - (2 ^ 3) = 3
   11 - - 2 ^ 3 = 3
    11 - 2 ^ $y = 3

and under 3.3.14.5:

  11 - 2 ^ 4 = 27
11 - 2.0 ^ 4 = -5
11 - 2e0 ^ 4 = -5
11 - '2' ^ 4 = -5
 11 - $x ^ 4 = -5
11 - (2 ^ 4) = -5
11 - - 2 ^ 4 = -5
 11 - 2 ^ $y = 27

  11 - 2 ^ 3 = 3
11 - 2.0 ^ 3 = 3
11 - 2e0 ^ 3 = 3
11 - '2' ^ 3 = 3
 11 - $x ^ 3 = 3
11 - (2 ^ 3) = 3
11 - - 2 ^ 3 = 3
 11 - 2 ^ $y = 3

Two possible explanations for this behaviour:

  1. binary minus is misinterpreted as unary minus:
    • The minus has two functions - once as a binary minus operator and once as a unary sign operator.
    • The tricky thing about this is that the binary operator has a lower priority than the power operator.
    • The sign operator, on the other hand, has a higher priority (in contrast to mathematics) than the power operator.
    • This leads to the implicit execution (-2)^4
    • The basic problem here, however, is that even if the minus here is only interpreted as a sign operator, we still lack a binary operator that links the right side with the 11. The parser seems to assume a plus operator for this.
    • Furthermore, there is no indication in the AutoIt documentation so far that the sign operator has a higher valence than the power operator.
  1. the minus is executed twice:
    • the --Operator seem to be executed twice - once as a unary operator (sign) and once as a binary operator (the minus operation).
    • This leads to the implicit calculation 11 - (-(2^4))

Attachments (0)

Change History (6)

comment:1 Changed 3 years ago by Jpm

Hi,
the main problem was coming from a regression introduce by #3772
But it was still a pb with 3.3.14.5 which must return -5 all the time
The unary operator is not really handled in AutoIt
The fix has been sent to Jon

comment:2 Changed 3 years ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

comment:3 Changed 2 years ago by Jpm

  • Milestone set to 3.3.15.6
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed by revision [12735] in version: 3.3.15.6

comment:4 Changed 2 years ago by Jpm

  • Milestone changed from 3.3.15.6 to 3.3.16.1

Fixed by revision [12736] in version: 3.3.16.1

comment:5 Changed 2 years ago by Jon

  • Owner changed from Jpm to Jon

Fixed by revision [12757] in version: 3.3.16.1

comment:6 Changed 18 months ago by anonymous

Hum, with
ConsoleWrite((11 - 24) & @CRLF)
I'm still getting 27 in v3.3.16.1
It's computing 11 + (-2)
4

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.