jaenster Posted July 20, 2007 Share Posted July 20, 2007 SQRT function in autoit expandcollapse popup;The code is fully writen by jaenster :) ; Full time to made, 49 minutes. $return = _wortel("47") consolewrite($return&@crlf) $return = _wortel("49") consolewrite($return&@crlf) $return = _wortel("25") consolewrite($return&@crlf) $return = _wortel("1337") consolewrite($return&@crlf) func _wortel($Number) $Try = 0 $Highst = -1 $lowst = -1 $factor = 1 while 1 $Try += $factor if $try*$try = $number Then return $try ElseIf $try*$try > $number Then if $Highst = -1 or $try*$try < $Highst Then $Highst = $try * $try $try = $try -($factor*2) $factor = $factor/10 if $factor <= 0.0001 then return round($try,4) endif endif elseif $try*$try < $number Then if $lowst = -1 or $try*$try > $lowst Then $lowst = $try * $try endif endif if $try > $number then return $try endif wend endfunc -jaenster Link to comment Share on other sites More sharing options...
GtaSpider Posted July 20, 2007 Share Posted July 20, 2007 Hello uhm? Why do you make a UDF for a function that already exists? Mfg / Best Regards Spider www.AutoIt.de - Moderator of the German AutoIt Forum Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted July 20, 2007 Share Posted July 20, 2007 Carrot? Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
martin Posted July 21, 2007 Share Posted July 21, 2007 (edited) Hello uhm? Why do you make a UDF for a function that already exists? Mfg / Best Regards Spider May be he didn't realise or, maybe he likes to see how things could be done using fundamental simple statements. This can be useful if you have to work something out in another language which doesn't have the maths experssions that Autoit has. Finding the square root on a processor without a maths coprocessor requires a bit of thinking. You can test the idea in AutoIt and prove the result with Execute. Here's a similar way to find the square root which is a bit shorter. $return = _wortel("47") ConsoleWrite($return & @CRLF) $return = _wortel("49") ConsoleWrite($return & @CRLF) $return = _wortel("25") ConsoleWrite($return & @CRLF) $return = _wortel("1337") ConsoleWrite($return & @CRLF) Func _wortel($Number) $Try = 10;could be anything $factor = 10;could be anything must be bigger than accuracy required While $factor > 0.0001;accuracy required If $Try * $Try > $Number Then; if you want cube root have $Try*$try*$try here etc $factor /= 2 $Try -= $factor ElseIf $try < $number then $Try += $factor Else exitloop;we have exact answer EndIf WEnd return round($try,4) EndFunc ;==>_wortel But in AutoIt, the result of An is Exp(Log(A)*n) Edited July 21, 2007 by martin 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. Link to comment Share on other sites More sharing options...
1905russell Posted July 21, 2007 Share Posted July 21, 2007 Carrot? Exactly carrot or root.$wortel = 25^(1\2) ;square root = power of a half Link to comment Share on other sites More sharing options...
martin Posted July 21, 2007 Share Posted July 21, 2007 Exactly carrot or root.$wortel = 25^(1\2) ;square root = power of a halfAaaw, now you've ruined it all! That's much too simple. 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. Link to comment Share on other sites More sharing options...
poisonkiller Posted July 21, 2007 Share Posted July 21, 2007 (edited) Could someone smart explain this to me: If I run this script: $sqrt = Number(3^0.5);3^(1/2) MsgBox(0, "", $sqrt) it returns ~1.73, but when I replace ^ with * (3*0.5) then it returns 1.5 (i tried and calculator returns 1.5 too). What's the difference in ^ and *? EDIT: I found the answer for my question: (from help file) ^ Raises a number to the power. e.g. 2 ^ 4 (equals 16), * Multiplies two numbers. e.g. 20 * 10 (equals 200). My next question is, that can I make that calculation (3^0.5) in real life with pencil and paper (and how)? Edited July 21, 2007 by poisonkiller Link to comment Share on other sites More sharing options...
martin Posted July 22, 2007 Share Posted July 22, 2007 Could someone smart explain this to me: If I run this script: $sqrt = Number(3^0.5);3^(1/2) MsgBox(0, "", $sqrt) it returns ~1.73, but when I replace ^ with * (3*0.5) then it returns 1.5 (i tried and calculator returns 1.5 too). What's the difference in ^ and *? EDIT: I found the answer for my question: (from help file) ^ Raises a number to the power. e.g. 2 ^ 4 (equals 16), * Multiplies two numbers. e.g. 20 * 10 (equals 200). My next question is, that can I make that calculation (3^0.5) in real life with pencil and paper (and how)? Do you mean how can you calculate a square root by hand or do you mean how do you calculate any number to any power by hand? 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. Link to comment Share on other sites More sharing options...
poisonkiller Posted July 22, 2007 Share Posted July 22, 2007 Both, if possible. Link to comment Share on other sites More sharing options...
Fabry Posted July 22, 2007 Share Posted July 22, 2007 5^3/4 =4 √53then5^1/2=2 √51 =√5for the power you do this 54 means 5*5*5*5.There are the squares in table of mathe. A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center] Link to comment Share on other sites More sharing options...
poisonkiller Posted July 22, 2007 Share Posted July 22, 2007 But how do I calculate power with 0.5? (3^0.5) Link to comment Share on other sites More sharing options...
jaenster Posted July 22, 2007 Author Share Posted July 22, 2007 Yes but i made my source for: 1) To learn autoit beter 2) For fun 3) Maby somebody likes it, And learn something from me. -jaenster Link to comment Share on other sites More sharing options...
martin Posted July 22, 2007 Share Posted July 22, 2007 But how do I calculate power with 0.5? (3^0.5)Yes 3^0.5 is the square root of 3. It doesn't matter what the values are; x to the power y is x^y which is the same as 1/(x^-y)x^y is the same as Exp(log(x) * y) 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. Link to comment Share on other sites More sharing options...
poisonkiller Posted July 22, 2007 Share Posted July 22, 2007 No I mean how can I calculate 0.5^3 with pencil and paper... I know that 2^3 equals 9 and 1^3 equals 3, but what about 0.5^3? Link to comment Share on other sites More sharing options...
RazerM Posted July 22, 2007 Share Posted July 22, 2007 0.5*0.5*0.5 0.5(0.5*0.5) 0.5(0.25) 0.125 My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Fabry Posted July 22, 2007 Share Posted July 22, 2007 No I mean how can I calculate 0.5^3 with pencil and paper... I know that 2^3 equals 9 and 1^3 equals 3, but what about 0.5^3?You write reverse powerI know that 2^3 equals 923 =8 = 2*2*232 =9 = 3*313 =1 = 1*1*131 =3 = 3then I know that 2^3 equals 8 A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center] Link to comment Share on other sites More sharing options...
poisonkiller Posted July 22, 2007 Share Posted July 22, 2007 Woops, it seems I wrote numbers backwards... Ok, I try to explain once more: 2^3=8 because 2*2*2=8, 3^3=27 because 3*3*3=27, 9^0.5=3 because...? How can I calculate 9^0.5? Link to comment Share on other sites More sharing options...
Fabry Posted July 22, 2007 Share Posted July 22, 2007 a fractal power works thus:9⅔= 3√92then9½= 2√91=2√9=√9=3 A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center] Link to comment Share on other sites More sharing options...
martin Posted July 22, 2007 Share Posted July 22, 2007 (edited) No I mean how can I calculate 0.5^3 with pencil and paper... I know that 2^3 equals 9 and 1^3 equals 3, but what about 0.5^3?I don't think you do know that. 2^3 = 8, but 3^2 = 91^3 is 1, but 3^1 = 3Here is a good explanation of how to calculate square roots by hand. Edited July 22, 2007 by martin 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. Link to comment Share on other sites More sharing options...
1905russell Posted July 22, 2007 Share Posted July 22, 2007 Don't forget the first line of a square root script is always. If $number < 0 Then ConsoleWrite("Can't square root a negative number") else ConsoleWrite(($number ^ .5) & @CRLF) endif Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now