Code: Select all
d := 1
msgbox ((d) * (++d) * (++d))
; ---------------------------
; Test5.ahk
; ---------------------------
; 12
; ---------------------------
; OK
; ---------------------------
Code: Select all
d := 1
msgbox ((d) * (++d) * (++d))
; ---------------------------
; Test5.ahk
; ---------------------------
; 12
; ---------------------------
; OK
; ---------------------------
Code: Select all
#Requires AutoHotkey v2.0+
d := 1
msgbox ((d) " * " (++d) " * " (++d))
d := 1
msgbox ((d) * (++d) * (++d))
; ---------------------------
; Test5.ahk
; ---------------------------
; 12
; ---------------------------
; OK
; ---------------------------
Code: Select all
n := 1
MsgBox( 'AHK: ' . n * ++n * ++n . '`n'
'Javascript: ' . GetJS().eval('var n = 1; n * ++n * ++n') )
GetJS() {
static document := '', JS
if !document {
document := ComObject('HTMLFILE')
document.write('<meta http-equiv="X-UA-Compatible" content="IE=9">')
JS := document.parentWindow
(document.documentMode < 9 && JS.execScript())
}
return JS
}
Code: Select all
public class Main {
public static void main(String[] args) {
int n = 1;
System.out.println(n * ++n * ++n); // 6
}
}
Thx for the comparisons. I know very little about the low level operations between memory and registers, so could not argue in either direction, based on the explanation above. I think your comparison is stronger evidence towards a bug also. This specific instruction set is fairly uncommon so hopefully we don't see this issue very often or at all. But you have to wonder if it can creep in undetected in some circumstances. Maybe I can take advantage of it to double my bank account.
Code: Select all
#Requires AutoHotkey v2.0
d := 1
MsgBox d * (++d) ; 2 * 2 = 4
d := 1
MsgBox (++d) * (++d) * d ; (3 * 3) * 3 = 27 ???
d := 1
MsgBox d * (++d) * (++d) ; (2 * 2) * 3 = 12
d := 1
MsgBox (++d) * d * (++d) ; (2 * 2) * 3 = 12
The second example, adding to 27, surprised me the most.The operation is performed and its result is used by the next operation.
Code: Select all
d := 1
multiply := ++d * ++d ; 2 * 3 := 6
MsgBox % Multiply ; 9 -> (3*3)
d := 1
division := ++d / ++d ; 2 / 3 := .667
MsgBox % division ; 1.0 -> (3/3)
d := 1
subtract := ++d - ++d ; 2 - 3 := -1
MsgBox % subtract ; 0 -> (3-3)
d := 1
addition := ++d + ++d ; 2 + 3 := 5
MsgBox % addition ; 6 -> (3+3)
Code: Select all
d := 1
MsgBox d * ++d ; expected 2, shows 4
Code: Select all
#Requires AutoHotkey v2.0
d := 1
MsgBox (d := d + 1) * d
Does my post above not cover this? Is there more going on? As you pointed out (d := d + 1), this is happening behind the scenes by mistake just before the first ++d is encountered (but only when the ++d is in the first or second position, as far as I can tell)
Oh... ok... I thought maybe I missed some other clues that invalidated the example. I have not found any other clues to indicate there is more going on, but there might be with further investigation. @lexikos can probably identify the cause in about 10 seconds.
Code: Select all
MsgBox 1 / 1