# 4 Brand new Math Funcs!

## Recommended Posts

Hello,

I was looking in the helpfile and I saw "_Min(), _Max()" and some "Is" stuff.

• _Half()
• _Double()
• _IsHalf()
• _IsDouble()
```; #FUNCTION# =================================================================================================
; Name...........: _Half()
; Description ...: Counts the half of the number
; Syntax.........: _Half(\$s_Num)
; Parameters ....: \$s_Num = The number
; Errors ........: -
; Return values .: \$s_Result
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Double(), _IsDouble(), _IsHalf()
; Link ..........: -
; Example .......: Yes
;                       MsgBox(0, Default, "The half of 10 is: " & _Half(10))
; #FUNCTION# =================================================================================================
Func _Half(\$s_Num)
\$s_Result = \$s_Num / 2
Return \$s_Result
EndFunc     ;==> _Half()

; #FUNCTION# =================================================================================================
; Name...........: _Double()
; Description ...: Get the double of the number
; Syntax.........: _Double(\$s_Num)
; Parameters ....: \$s_Num = The number
; Errors ........: -
; Return values .: \$s_Result
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Half(), _IsHalf(), _IsDouble()
; Link ..........: -
; Example .......: Yes
;                       MsgBox(0, Default, "The double of 10 is: " & _Double(10))
; #FUNCTION# =================================================================================================
Func _Double(\$s_Num)
\$s_Result = \$s_Num * 2
Return \$s_Result
EndFunc     ;==> _Double()

; #FUNCTION# =================================================================================================
; Name...........: _IsHalf()
; Description ...: Checks the \$s_Num is the half of \$s_First
; Syntax.........: _IsHalf(\$s_Num, \$s_First)
; Parameters ....:  \$s_Num = The first number
;                       \$s_First = The second number
; Errors ........: -
; Return values .: 1 If \$s_Num is the half of \$s_First
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Half(), _Double(), _IsDouble()
; Link ..........: -
; Example .......: Yes
;                       MsgBox(0, Default, "Is 5 the half of 10?" & @CRLF & _IsHalf(5, 10))
; #FUNCTION# =================================================================================================
Func _IsHalf(\$s_Num, \$s_First)
If \$s_First / 2 = \$s_Num Then
Return 1
Else
Return 0
EndIf
EndFunc     ;==> _IsHalf()

; #FUNCTION# =================================================================================================
; Name...........: _IsDouble()
; Description ...: Checks if \$s_Last is the double of \$s_Num
; Syntax.........: _IsDouble(\$s_Num, \$s_Last)
; Parameters ....: \$s_Num = The first number
;                       \$s_Last = The second number
; Errors ........: -
; Return values .: 1 If \$s_Last if the double of \$s_Num
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: -
; Link ..........: -
; Example .......: Yes
;                       MsgBox(0, Default, "Is 10 the double of 5?" & @CRLF & _IsDouble(5, 10))
; #FUNCTION# =================================================================================================
Func _IsDouble(\$s_Num, \$s_Last)
If \$s_Num * 2 = \$s_Last Then
Return 1
Else
Return 0
EndIf
EndFunc     ;==> _IsDouble()```

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

##### Share on other sites

I'm pretty sure that it would be faster for each of these if you were to just write out the statement. Like this:

`\$newNumber = Half(\$otherNumber)`

Compared to

`\$newNumber = \$otherNumber / 2`

You save at least two chars doing it the second way.

They're good example functions though...

Edited by Achilles

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

##### Share on other sites

So you are actualy saying, that I sould rename the \$vars?

And that this is a good example?

Ty I think

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

##### Share on other sites

So you are actualy saying, that I sould rename the \$vars?

And that this is a good example?

Not quite what he said.

##### Share on other sites

@AlmarM; you can add new one, three-quarters, something like :

If IsthreeQuarters = 0 Then ...

Just kidding.

.

eMyvnE

##### Share on other sites

Too little useful your functions. Like an example is good.

When the words fail... music speaks

##### Share on other sites

Aiight!

Well, I tought it was OK.

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

##### Share on other sites

Nice job, hope you add more.

You didn't declare your variables as Local in the functions so any existing variables will be overwritten but you could just instead do this.. I guess readability was what your aiming for, but written this way (see below) seems more logical.

```; #FUNCTION# =================================================================================================
; Name...........: _Half()
; Description ...: Counts the half of the number
; Syntax.........: _Half(\$s_Num)
; Parameters ....: \$s_Num = The number
; Errors ........: -
; Return values .: \$s_Result
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Double(), _IsDouble(), _IsHalf()
; Link ..........: -
; Example .......: Yes
;                  MsgBox(0, Default, "The half of 10 is: " & _Half(10))
; #FUNCTION# =================================================================================================
Func _Half(\$s_Num)
Return \$s_Num / 2
EndFunc  ;==> _Half()

; #FUNCTION# =================================================================================================
; Name...........: _Double()
; Description ...: Get the double of the number
; Syntax.........: _Double(\$s_Num)
; Parameters ....: \$s_Num = The number
; Errors ........: -
; Return values .: \$s_Result
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Half(), _IsHalf(), _IsDouble()
; Link ..........: -
; Example .......: Yes
;                  MsgBox(0, Default, "The double of 10 is: " & _Double(10))
; #FUNCTION# =================================================================================================
Func _Double(\$s_Num)
Return \$s_Num * 2
EndFunc  ;==> _Double()

; #FUNCTION# =================================================================================================
; Name...........: _IsHalf()
; Description ...: Checks the \$s_Num is the half of \$s_First
; Syntax.........: _IsHalf(\$s_Num, \$s_First)
; Parameters ....:  \$s_Num = The first number
;                  \$s_First = The second number
; Errors ........: -
; Return values .: 1 If \$s_Num is the half of \$s_First
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: _Half(), _Double(), _IsDouble()
; Link ..........: -
; Example .......: Yes
;                  MsgBox(0, Default, "Is 5 the half of 10?" & @CRLF & _IsHalf(5, 10))
; #FUNCTION# =================================================================================================
Func _IsHalf(\$s_Num, \$s_First)
Return _Half(\$s_First) = \$s_Num
EndFunc  ;==> _IsHalf()

; #FUNCTION# =================================================================================================
; Name...........: _IsDouble()
; Description ...: Checks if \$s_Last is the double of \$s_Num
; Syntax.........: _IsDouble(\$s_Num, \$s_Last)
; Parameters ....: \$s_Num = The first number
;                  \$s_Last = The second number
; Errors ........: -
; Return values .: 1 If \$s_Last if the double of \$s_Num
; Author ........: Almar Mulder (AlmarM, almar_mulder[at]live[dot]com)
; Modified.......: -
; Remarks .......: -
; Related .......: -
; Link ..........: -
; Example .......: Yes
;                  MsgBox(0, Default, "Is 10 the double of 5?" & @CRLF & _IsDouble(5, 10))
; #FUNCTION# =================================================================================================
Func _IsDouble(\$s_Num, \$s_Last)
Return _Double(\$s_Num) = \$s_Last
EndFunc  ;==> _IsDouble()```

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

## 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