Sign in to follow this  
Followers 0
gazai

math function in AutoIt

5 posts in this topic

I'm a newbie to AutoIt. I've using other staff for a while (VB, Perl) and starting to learning this unique language, thanks to the great efforts put up for this wonderful platform. I plan to migrate some of my perl codes into AutoIt.

I check the function list on Wiki, and, surprisingly, found very limited math functions. I'm talking about simple math functions such as average, standard deviation, percentile.

How can I get these functions for AutoIt?

Any advice/suggestion is much appreciated.

Share this post


Link to post
Share on other sites



By writing them. Another option is to search the forum, especially Example Scripts, for things you need. Many of those have already been written and posted. For example: Standard Deviation Calculator

:blink:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I'm a newbie to AutoIt. I've using other staff for a while (VB, Perl) and starting to learning this unique language, thanks to the great efforts put up for this wonderful platform. I plan to migrate some of my perl codes into AutoIt.

I check the function list on Wiki, and, surprisingly, found very limited math functions. I'm talking about simple math functions such as average, standard deviation, percentile.

How can I get these functions for AutoIt?

Any advice/suggestion is much appreciated.

Simple Average Calc (Took 10 mins to write):

Global $aTest[10] = [5,4,6,5,45,32,60,56,2,55]
Global $aTest2[11] = [10,5,4,6,5,45,32,60,56,2,55]
$rtn = _Avg($aTest, 0)
$rtn2 = _Avg($aTest2, 1)
ConsoleWrite("AVG1: " & $rtn & " AVG2: " & $rtn2 & @CRLF)

;_Avg ($aVars, [$iIndex = 0])
;$aVars = Array Input of vars to calc
;$iIndex = 0 or 1 base array
;Sucess: Returns Average
;Failure: Returns -1 if not an array
Func _Avg ($aVars, $iIndex = 0)
    Local $equation = 0
    If Not IsArray($aVars) Then Return -1
    If $iIndex = 1 Then
        For $n = 1 To UBound($aVars) - 1
            $equation += $aVars[$n]
        Next
        Return ($equation / (UBound($aVars) - 1))
    Else
        For $n = 0 To UBound($aVars) - 1
            $equation += $aVars[$n]
        Next
        Return ($equation / (UBound($aVars)))
    EndIf
EndFunc

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for the advices! It at least gives me a sense what is expected when I need them.

When build a slightly complicated algorithm from these home-browned calculations, it may be easily crashed. This will end up spending more time to deal with the 'exceptions', or the "unmaintainable in the end".

Edited by gazai

Share this post


Link to post
Share on other sites

If you code something yourself and only limit it to personal use, you don't really need to invest too much on robustness and error handling since you know to avoid what will break your script.

Good coding practice and standards makes easy to reuse and maintain code, although "reusability" in AutoIt may not always be in the traditional sense unless you're one of those that like to build and use a personal "include" library.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0