Ahk Topic


SM_Solve(expression, ahk=false)

  • Solves a Mathematical expression in a string . The ahk param is to make SM_Solve() use the AutoHotkey's +-*/ instead of its own. Enable it if you are sure that the calculation you are doing can be calculated with AHK only. It may give faster results.
  • SM_Solve() supports infinetly large numbers and its +-/* is powered by the respective custom functions (SM_Add, SM_Multiply, SM_Divide).
  • It supports functions (default and user-defined) , expressions inside expressions and nesting via (...) brackets.
  • You can use ^ or ** calulate power and ! to calculate factorial on the go.
  • Scientific notation numbers can also be used as they are in the function.
  • SM_Solve() solves expressions in the traditional left-to-right format for the operators +-*/ and not in the BODMAS format. Use nesting to achieve your desired results.
  • Use p or c for Permuation or Combination. (4c2 * 5c3)
  • Users are highly recommended to use this function to solve expressions rather than using the individual functions in this library.
  • Users are recommended to use Nesting via (...) brackets wherever necessary.
msgbox % SM_Solve("4 + ( 2*( 3+(4-2)*round(2.5) ) ) + (5c2)**(4c3)")
msgbox % "The gravity on earth is: " SM_Solve("(6.67e-11 * 5.978e24) / 6.378e6^2")

var = sqrt(10!) - ( 2**5 + 5*8 )
msgbox,% SM_Solve(var)
;In the above example, var has the equation.
  • You can also use global variables inside SM_Solve() . These variables must be surrounded by % to make SM_Solve() see them as variables. Below is an example to demonstrate the purpose.
global h := "6.6260695729e-34"
global c := "299792458"
global lemda := "5400e-10"

msgbox % ans := SM_Solve("%h%*%c%\%lemda%") ;note the %..% here

msgbox % SM_ToExp(ans)                      ;converting to Exponential form
  • To use functions with alphabetic identifiers such as e, c or p , enclose them with %...% . See the following example -
msgbox % SM_Solve(" %sin(1.59)% e %log(1000)% ")
;The above is equal to  sin(1.59) e (log(1000))
;that is - sin(1.59) * 10^log(1000)

msgbox % SM_Solve( " 4^sin(3.14) + 5c%log(100)% + %sin(1.59)%e%log(1000)% + log(1000)! " )
;As you see , the identifiers ^ and ! dont require functions in %....% , though you can always use the %...% if you wish.


  • Adds two infinetly large numbers . Supports decimal and negatives.
  • Please feed numbers into the function as strings (See below)
number1 = 3292389200000000000382398232309.239230923092302390239230
number2 = 239209239230290239239049349309403434.34930909090
Msgbox,% SM_Add(number1 ,number2)
Msgbox,% SM_Add(number1, "-" number2)   ;Notice the use of "-" to subtract

;Notice the use of = in place of :=

SM_Multiply(n1, n2)
SM_Divide(dividend, divisor, length=10)

  • Feed large numbers as Strings
  • Better recommended to keep the length param of SM_Divide as 10 which is default. If you want more preciseness you can move it to anything.
  • SM_Divide() has smartround which means something like 0.000000003433423 with a length 3 will not give 0.000 but 0.00000000343
MsgBox,% SM_Divide("434343455677690909087534208967834434444.5656", "8989998989898909090909009909090909090908656454520", 10)
msgbox,% SM_Divide("22","7",100)  ;--- 100 Decimal places
MsgBox,% SM_Multiply("111111111111111111111111111111111111111111.111","55555555555555555555555555555555555555555555.555")

SM_UniquePMT(series, Index, delimiter=",")

  • Gives unique Permuation for a given Index where Index < No of Permutations
  • Make Index = All to list down all possible permutations
msgbox,% SM_UniquePMT("avi,annat,koiaur,aurkoi", "All")  ;no of permutation =  24
msgbox,% SM_UniquePMT("abd", 3);no of permutation = 6


Returns factorial of any natural number
msgbox % SM_fact(50)

SM_Greater(number1, number2, trueforequal=true)

Returns 1 (true) if number1 is greater than number2
If 'trueforequal' is true , it returns 1 also when number1 = number2
msgbox % SM_Greater("2382938239832923", "23923892323232.23923323", true)

if SM_Greater("23923892323", "23823923923")
    msgbox True
    msgbox False


Returns a number in perfect form removing all extra zeroes and decimals
msgbox % SM_Prefect("00.0022323238230000")

SM_Pow(number, Power)

Returns 'number' to the power 'Power'
Suitable for large numbers.
msgbox % SM_Pow("121", 20)

if SM_Greater(SM_Pow("123", 10) , "23823923923")
   msgbox True
    msgbox False

SM_Mod(number1, number2)

Mod of number1 with respect to number2
msgbox % SM_Mod("122304393493", "232434")

if ( SM_Mod("1202323023923023022", 2) == "0" )
    msgbox, The number is even
    msgbox, The number is odd

SM_Round(number, decimals)

Rounds a number to the specified decimal numbers.
Doesnt't support negative value of decimals i.e. no trimming before decimal is supported.
msgbox % SM_Round("23023923023920332.239239232323129", 5)

SM_Floor(number) || SM_Ceil(number)

Returns Floor() || Ceil() of a number.
To know about these functions, see Autohotkey help file
msgbox % SM_Floor("2323023902323.210")
msgbox % SM_Ceil("-23023023.23")

SM_ToExp(number, decimals)

Returns any number in exponential form like
The decimals param rounds of the the scientific number to have as many decimals you like.
msgbox % SM_ToExp("994556989569454.2334423723900")
;returns --


Converts a number from scientific number format to a real number.
Msgbox % SM_fromexp("6.45423e10")

SM_e(N, auto=1)

Returns 'e' (exponential factor) to the power 'N' . auto = 1 enables smart rounding for faster results . Call auto as false (0) for totally accurate results. (may be slow).
msgbox % SM_e(10)
;Returns --

SM_Number2Base(N, base=16)
SM_Base2Number(H, base=16)

SM_Number2Base converts number N to base base
SM_Base2Number converts number H in base base to a real number (which is in base 10).
msgbox % t:=SM_Number2Base("10485761048", 2)  ;base 2
msgbox % f:=SM_Number2base("10485761048", 32) ;base 32
;now convert them back to numbers
msgbox % SM_Base2Number(t, 2) "`n" SM_Base2Number(f, 32)