Choose integer size

Propose new features and changes
buttshark
Posts: 62
Joined: 22 Apr 2017, 20:57

Choose integer size

31 Dec 2017, 16:40

It would be nice to be able to choose and stick with the size of an integer for a variable, because ahk automatically changing them can make them difficult to work with when doing bitwise operations. Simple example and current workaround:

Code: Select all

msgbox, % ~~-1 ;-1 is 0xFFFFFFFFFFFFFFFF. ~ that is 0x00000000. ~ that is 0xFFFFFFFF
;workaround:
;	x := -1
;	is64Bit := x < 0 OR x > 0xFFFFFFFF
;	y := ~~x
;	if(is64Bit AND y >= 0 AND y <= 0xFFFFFFFF)
;	{
;		y |= 0x7FFFFFFF00000000
;		y := y << 1 >> 1 ;the negative bit is special for some reason
;	}
;	msgbox, % y
Thanks :)
I have no idea what I'm doing.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Choose integer size

31 Dec 2017, 17:37

As far as I am aware, the ~ operator is the only special case; all other operators are purely 64-bit.

You can just do n ^ -1 instead of ~n.

Also, see commit 247bf90f (v2-alpha).
y := y << 1 >> 1 ;the negative bit is special for some reason
This is standard arithmetic shift.
Instead of being filled with all 0s, as in logical shift, when shifting to the right, the leftmost bit (usually the sign bit in signed integer representations) is replicated to fill in all the vacant positions (this is a kind of sign extension).
Source: Arithmetic shift - Wikipedia
buttshark
Posts: 62
Joined: 22 Apr 2017, 20:57

Re: Choose integer size

31 Dec 2017, 18:03

lexikos wrote:Also, see commit 247bf90f (v2-alpha).
Okay, cool. So is this for just future AutoHotkey_L?

lexikos wrote:
y := y << 1 >> 1 ;the negative bit is special for some reason
This is standard arithmetic shift.
Ah, I see. I was wondering about the bit shift in my other post, too. But still,

Code: Select all

y |= 0xFFFFFFFF00000000
replacing

Code: Select all

y |= 0x7FFFFFFF00000000
y := y << 1 >> 1
doesn't work, and I'm not sure why
I have no idea what I'm doing.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Choose integer size

01 Jan 2018, 04:13

So is this for just future AutoHotkey_L?
Sorry, what? It's for v2 only. Scripts rely on the current behaviour.
y |= 0xFFFFFFFF00000000
That's because
Commands, functions, and expressions that accept numeric inputs generally support 15 digits of precision for floating point values. For integers, 64-bit signed values are supported, which range from -9223372036854775808 (-0x8000000000000000) to 9223372036854775807 (0x7FFFFFFFFFFFFFFF). Any integer constants outside this range are not supported and might yield inconsistent results. By contrast, arithmetic operations on integers wrap around upon overflow (e.g. 0x7FFFFFFFFFFFFFFF + 1 = -0x8000000000000000).
Source: Variables and Expressions
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Choose integer size

01 Jan 2018, 07:01

It would be nice to have up to 0xFFFF FFFF FFFF FFFF though for the use of binaries ( and convert it internally to -1 in thise case )
Recommends AHK Studio

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 23 guests