Sign in to follow this  
Followers 0
DaProgrammer

Div Function

2 posts in this topic

#1 ·  Posted (edited)

div.au3

;===============================================================================
      ;
      ; Function Name:  _Div()
      ; Description:      Devides $Num by $Devidant.
      ; Parameter(s): $Num - The Number you are deviding.
      ;                 $Devidant - The Number you are deviding by.
      ;                
      ;                 $Result[0] - The Whole Result
      ;                 $Result[1] - The remainder.
      ;
      ; Requirement(s):   None.
      ; Return Value(s):  The Whole Number and the remainder.
      ;                      @error is set to 1 if Devidant = 0.
      ; Author(s):      KJ
      ;
      ;===============================================================================
       
       Func _Div($Num,$Devidant)
       Local $Result[2]
       
       If $Num < 0 Then $Num = -$Num
       If $Devidant < 0 Then $Devidant = -$Devidant
       If $Devidant = 0 Then
        SetError(1)
        Return
       EndIf
        
        If $Num > $Devidant Then
            $Result[0] = Floor($Num/$Devidant)
            $Result[1] = $Num - ($Result[0]*$Devidant)
        
        ElseIf $Num = $Devidant Then
            $Result[0] = 1
            $Result[1] = 0
        
        ElseIf $Num < $Devidant Then
            $Result[0] = 0
            $Result[1] = $Num
        EndIf
       
       Return $Result
       EndFunc

Sample.au3

#include "div.au3"
 $a=_Div(50,9)
 If @error=0 Then MsgBox(0,"",$a[0] & "  " & $a[1])

what u all think ?

i personally think it should be addded to the autoit user functions.

Edited by DaProgrammer

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