Jump to content

Recommended Posts

Posted (edited)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.12.1
 Author:         Athiwat Chunlakhan

 Script Function:
    _Mod($b, $e, $m)
    
    Submit as an UDF

#ce ----------------------------------------------------------------------------

$b = 4
$e = 13
$m = 497

MsgBox(0, 'Mod', Mod($b ^ $e, $m)) ; This return the right value
MsgBox(0, '_Mod', _Mod($b, $e, $m)) ; This return the right value

$b = 444
$e = 5555
$m = 455

MsgBox(0, 'Mod', Mod($b ^ $e, $m)) ; This return the WRONG value
MsgBox(0, '_Mod', _Mod($b, $e, $m)) ; This return the right value

Func _Mod($b, $e, $m) ; Base, power, mod
    Local $c = 1
    For $i = 1 to  $e
        $c = Mod($c * $b, $m)
    Next
    Return $c
EndFunc   ;==>_Mod

Edited by athiwatc
Posted

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.12.1

Author: Athiwat Chunlakhan

Script Function:

_Mod($b, $e, $m)

Submit as an UDF

#ce ----------------------------------------------------------------------------

$b = 4

$e = 13

$m = 497

MsgBox(0, 'Mod', Mod($b ^ $e, $m)) ; This return the right value

MsgBox(0, '_Mod', _Mod($b, $e, $m)) ; This return the right value

$b = 444

$e = 5555

$m = 455

MsgBox(0, 'Mod', Mod($b ^ $e, $m)) ; This return the WRONG value

MsgBox(0, '_Mod', _Mod($b, $e, $m)) ; This return the right value

Func _Mod($b, $e, $m) ; Base, power, mod

Local $c = 1, $eIN = 0

While $eIN < $e

$eIN += 1

$c = Mod($c * $b, $m)

WEnd

Return $c

EndFunc ;==>_Mod

Code tags around your scripst would improve the look.

Looks very similar to this.. I think the for/next loop would be faster.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

Oops, I don't know Its already there

Well great minds you know :)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...