Cant use "**" with A_Now Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Cant use "**" with A_Now

Post by RaptorX » 30 Mar 2023, 12:49

Hi guys.

I just wanted to get a quick number that had more than 10 digits and tried A_Now**3 but got the same negative number every time: -9223372036854775808.

I decided to try a loop and this is what I have:

Code: Select all

f1::
loop 1000
{
	tooltip  % "(" a_now ") -> " a_now ** 3
	sleep 10
}

tooltip 
return
I see A_Now updating but the number on the right remains static.

Multiplying the code works fine i.e.: A_Now * 3.

32/64 bit versions of v1 produce the same issue.
I tried the same code on 32/64 bit v2 and it works as expected on both.

This might be a bug?
Projects:
AHK-ToolKit

gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: Cant use "**" with A_Now

Post by gregster » 30 Mar 2023, 12:53

Probably not a bug, but the variable capacity is simply exceeded: https://www.autohotkey.com/docs/v1/Variables.htm#cap

For v1, you can try https://github.com/aviaryan/autohotkey-scripts/blob/master/Functions/Maths.ahk

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: Cant use "**" with A_Now

Post by RaptorX » 30 Mar 2023, 14:11

Thought about that but A_now * A_now * A_now works fine and dandy...
Also it works fine in v2.
Projects:
AHK-ToolKit

gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: Cant use "**" with A_Now

Post by gregster » 30 Mar 2023, 18:06

RaptorX wrote:
30 Mar 2023, 14:11
Thought about that but A_now * A_now * A_now works fine and dandy...
Also it works fine in v2.
I mean, you get a result, but is it correct? I get many negative results for A_now * A_now * A_now when repeated in v1, which seems rather unlikely :shifty:

In v2, I also got some negative results - which still seems unlikely, if you are expecting a correct result.


I also think I should get much bigger numbers for A_now**3 or A_now * A_now * A_now than I am actually getting. Or do you think that variable capacity is not a thing? ;) These calculations might create different results, but both results should be off by miles.

Do you have some example calculations of that range which can get reproduced and are actually correct ? Afaik, those integers are just too big.

Memo:
Spoiler

User avatar
flyingDman
Posts: 2823
Joined: 29 Sep 2013, 19:01

Re: Cant use "**" with A_Now

Post by flyingDman » 30 Mar 2023, 18:22

A_now**3 is 8,279,591,533,288,750,553,385,246,737,173,521,337,000 a tad over the AHK limit.... ;)
14.3 & 1.3.7

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: Cant use "**" with A_Now

Post by RaptorX » 30 Mar 2023, 18:48

Let me see if I clarify a few things xD

I dont mind if the result is correct or not because i just wanted a number, I was just interested in the fact that A_Now ** 3 works in v2 but doesnt work in v1.

I am not saving that information into any variables, so I am not really sure how variable size might be a limit, unless you are referring to the difference of the int size in either 32/64 bit versions of AHK which is probably what you are alluding to.

The reason why you get negative numbers is because signed integers have a range of numbers and IIRC they kind of wrap around (which is what I am expecting in v1 but is not happening).

So again, I would like to focus more on the fact that the exact same code gives me values in v2 but fails in v1... and if that is expected or not, because I couldnt tell from the documentation.

Maybe @lexikos might have a quick answer for this one. :P
Projects:
AHK-ToolKit

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: Cant use "**" with A_Now

Post by RaptorX » 30 Mar 2023, 18:49

flyingDman wrote:
30 Mar 2023, 18:22
A_now**3 is 8,279,591,533,288,750,553,385,246,737,173,521,337,000 a tad over the AHK limit.... ;)
are you suggesting that v2 doesnt have that limit? :P
Projects:
AHK-ToolKit

gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: Cant use "**" with A_Now

Post by gregster » 30 Mar 2023, 19:01

I don't think that AHK intends to guarantee any specific (right or wrong) results outside of the documented variable capacity.

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: Cant use "**" with A_Now

Post by RaptorX » 31 Mar 2023, 08:42

gregster wrote:
30 Mar 2023, 19:01
I don't think that AHK intends to guarantee any specific (right or wrong) results outside of the documented variable capacity.
Can you clarify which variable you are referring to in this code?

Code: Select all

Msgbox % A_Now**3
If I was saving the results to a variable I would understand what you mean. But right now is not clear to me which variable capacity you are referring to.
Projects:
AHK-ToolKit

gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: Cant use "**" with A_Now

Post by gregster » 31 Mar 2023, 08:56

Well, I am just not surprised that calculating with numbers of that size can cause inconsistencies, assigned to a variable or not.
If the shown inconsistency is covered by the linked v1 docs is perhaps debatable, but I have always interpreted them like that. (The v2 docs differ a bit in that regard, seeming to actually ensure a wrap around. Also: "Integer constants and numeric strings outside of the supported range (of 64-bit signed integers) now overflow/wrap around, instead of being capped at the min/max value." -> v2 changes)

Rohwedder
Posts: 7687
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Cant use "**" with A_Now

Post by Rohwedder » 31 Mar 2023, 10:02

Hallo,

Code: Select all

F1::
MsgBox,% "Autohotkeys largest integer:`n (1<<-1)-1 = " (1<<-1)-1
MsgBox,% "once it is exceeded, the result is negative:`n" (1<<-1) "`n" (1<<-1)+999 "`n" a_now**3

User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: Cant use "**" with A_Now

Post by RaptorX » 01 Apr 2023, 07:12

gregster wrote:
31 Mar 2023, 08:56
Also: "Integer constants and numeric strings outside of the supported range (of 64-bit signed integers) now overflow/wrap around, instead of being capped at the min/max value." -> v2 changes)
I think this answers my question, seems like v1 doesn't wrap the numbers around which is why once exceeded i get the same number all the time (which was the unexpected part) thanks!
gregster wrote:
31 Mar 2023, 08:56
Well, I am just not surprised that calculating with numbers of that size can cause inconsistencies, assigned to a variable or not.
Well, I was not expecting it to give me correct values, but i was expecting it to produce different numbers on each loop (correct or otherwise), which is what happens in v2.
Projects:
AHK-ToolKit

just me
Posts: 9498
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cant use "**" with A_Now  Topic is solved

Post by just me » 01 Apr 2023, 08:08

Concepts And Conventions -> Pure Numbers wrote: v1:
Integers must be within the range -9223372036854775808 (-0x8000000000000000, or -263) to 9223372036854775807 (0x7FFFFFFFFFFFFFFF, or 263-1). Although larger values can be contained within a string, any attempt to convert the string to a number (such as by using it in a math operation) might yield inconsistent results.

v2:
Integers must be within the signed 64-bit range; that is, -9223372036854775808 (-0x8000000000000000, or -263) to 9223372036854775807 (0x7FFFFFFFFFFFFFFF, or 263-1). If an integer constant in an expression is outside this range, only the low 64 bits are used (the value is truncated). Although larger values can be contained within a string, any attempt to convert the string to a number (such as by using it in a math operation) will cause it to be similarly truncated.

Emile HasKey
Posts: 27
Joined: 06 Mar 2022, 17:45

Re: Cant use "**" with A_Now

Post by Emile HasKey » 16 Apr 2023, 16:37

I took a look at the source code.
For SYM_POWER, when both values are integers:
In AHK v1, it casts to doubles, exponentiates, then casts to Int64.
In AHK v2, it does repeated multiplication.

As AHK code:

Code: Select all

; AHK v1/v2 integer exponentiation:
now := A_Now
output := (now**3)
. "`n" Format("{:i}", (now+0.0)**3.0) ; like AHK v1
. "`n" Format("{:i}", now*now*now) ; like AHK v2
MsgBox % output
return

string to a number
One function in the source code that converts strings to numbers is ATOF.
ATOF uses _tcstoi64, which corresponds to _wcstoi64 and _strtoi64 (Unicode and ANSI respectively).

Post Reply

Return to “Ask for Help (v1)”