[Feature Request] Add "Sign" function

Discuss the future of the AutoHotkey language
AndreVallestero
Posts: 2
Joined: 14 Aug 2018, 12:34
Contact:

[Feature Request] Add "Sign" function

14 Aug 2018, 12:53

A "Sign" function would be very useful in many cases where only a max distance of 1 is allowed which is a case I have encountered many times with directional mouse movement. Sign() would take any number and would return -1 for a negative value, 0 for a 0 value and 1 for a positive value.

Here's a sample implementation for C++:

return -1 + (int)(number > -1) + (int)(number > 0);
Last edited by AndreVallestero on 14 Aug 2018, 14:33, edited 1 time in total.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [Feature Request] Add "Sign" function

14 Aug 2018, 14:07

Why not write it yourself? e.g.:

Code: Select all

sign(nr) {
	return (nr>0)-(nr<0)
}
Recommends AHK Studio
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [Feature Request] Add "Sign" function

14 Aug 2018, 15:40

- I know it's relatively minor but I would agree that this should be added.
- There's a certain selection of basic functions that should be built into all programming languages and I have been writing an article on this that I intend to publish, comparing 4 programming languages.
- I would want AutoHotkey to be a model language in this regard. Cheers.

- New functions I have in mind:
ATan2(vNumY, vNumX)
Pow(vNum1, vNum2)
Sign(vNum)
- Amendments I have in mind (additional parameters):
Ceil(vNum, vDP:=0)
Floor(vNum, vDP:=0)
Log(vNum, vBase:=10)
- Possibly (names could be different):
BaseToDec
Between
DecToBase
MCeil(vNum, vMult:=1)
MFloor(vNum, vMult:=1)
MRound(vNum, vMult:=1) ;round to nearest multiple

Code: Select all

JEE_Sign(vNum)
{
	;return (vNum = 0) ? 0 : Round(vNum/Abs(vNum)) ;logically more secure
	;return Round(vNum/Abs(vNum)) ;also works
	return (vNum > 0) ? 1 : (vNum < 0) ? -1 : 0
}
- Btw @nnnik, nice implementation.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [Feature Request] Add "Sign" function

22 Aug 2018, 10:23

- Something else that could be worth considering is a mod operator. This is very useful for when converting between AutoHotkey and other programming languages.

- I've written some potential code for some of these functions, here:
C++: AHK source code: potential functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23&t=54392
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 28 guests