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);
[Feature Request] Add "Sign" function
-
- Posts: 2
- Joined: 14 Aug 2018, 12:34
- Contact:
[Feature Request] Add "Sign" function
Last edited by AndreVallestero on 14 Aug 2018, 14:33, edited 1 time in total.
Re: [Feature Request] Add "Sign" function
Why not write it yourself? e.g.:
Code: Select all
sign(nr) {
return (nr>0)-(nr<0)
}
Recommends AHK Studio
Re: [Feature Request] Add "Sign" function
- 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
- Btw @nnnik, nice implementation.
- 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
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: [Feature Request] Add "Sign" function
- 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
- 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
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 10 guests