# Extended maths UDF

## Recommended Posts

This is a nearly complete compilation of all the useful maths scrips and scraps I have seen over my time here. And I hope between this and jennicos primes suite we will have a practically complete set of maths functions!

BigInt's

Loosely based on Wus' functions, these form half the UDF, and are also the biggest let down as I can't quite get BigIntDivide to work . Nevertheless, as far as I know they are the only really complete (ish) set.

Edit: Eukalyptus' BigNum UDF is far more complete and generally better than mine, so I would advise using that instead.

Fibonacci

Just based on some school work I am doing on binet's formula (google it, its an interesting read!). Decided that since most of the other fibonacci generators are still adding togethor the last two it seems someone ought to show em how it should be done!

trig

The amount of confusion the current trig functions cause means this should help some people get by! Basically, before you had to enter in radians, and the return was in degrees. This just converts before / after to make sure its same in + same out! Also added is some Rad and deg functions, just for completion.

Misc

Most have been released before now in their own topics, such as my root and round functions. Quadratic is once again school work that I decided to add, mostly to test my StringRegExp skills

Pascal *NEW*

Only one function at the moment: _PascalGetLine. Read reply: for details. I may add some more functions here in a similar way to fibonnaci section if people are interested.

Mat

Edited by Mat

##### Share on other sites

Updated the source with a new function: _PascalGetLine.

It returns a specific line of pascals triangle, without recursively adding the above 2 values. It's probably got very little use... the only thing I am trying it out with is binomial coefficients, but I like the way it worked out. I am also pretty impressed that I was able to do it

I hope people decide to show some interest here soon, i'm practically talking to myself here.

Mat

##### Share on other sites

I think any efforts to get more maths functions into AutoIt are great, so well done!

I think you may be missing $sAng from _MathArcSin ($nIn) though.

What stage are you at in school? Calculus will open a whole new world of coding for you when you get to it.

I wish AutoIt had been about in the 90's when I studied maths properly.

I can see where you're going with the BigInt funcs, and it's a really good effort, but I think you may have been pipped at the post.

Keep up the good work!

.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

##### Share on other sites

I think any efforts to get more maths functions into AutoIt are great, so well done!

I think you may be missing $sAng from _MathArcSin ($nIn) though.

What stage are you at in school? Calculus will open a whole new world of coding for you when you get to it.

I wish AutoIt had been about in the 90's when I studied maths properly.

I can see where you're going with the BigInt funcs, and it's a really good effort, but I think you may have been pipped at the post.

Keep up the good work!

I'm taking my GCSE next month (a year early). Calculus is differentiation isn't it? I haven't thought about it much...

I never saw those bignums... but I wish I had! Thats is some very interesting scripting, I particularly like the way he's padded the numbers, I think thats very clever. The fact theres a seperator allowed too is a nice addition.

Thanks for the _MathArcSin thing too, I don't know how thats in there, my clipboard must have broken

Mat

##### Share on other sites

Looking at your round function and it looks really cool and comprehensive. That said, I think you need to say what the acceptable numbers are for each parameter in the header.

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

##### Share on other sites

I know what you mean,

I released that funtction alongside a more detailed page on what the options meant in this thread:

http://www.autoitscript.com/forum/index.php?showtopic=102686&view=findpost&p=728361

and this site:

http://auto-mat-ic.webs.com/Pages/UDFs/Rounding/Rounding.html

I am in the process of updating it to be a wiki page on my google code page (see sig). So it may not be perfect, and I have not tested the links for a long time... But they are on my google code page already.

There are also some constants, which I don't think made it into the udf ....

; #VARIABLES# ====================================================================================================================
;
; type
Global Const $RND_TYPE_DEFAULT = Default ; Decimal Places Global Const$RND_TYPE_DP          = 1       ;  Decimal Places        : 1.75643 to 3 dp = 1.756
Global Const $RND_TYPE_SF = 2 ; Significant figures : 1.75643 to 3 sf = 1.76 Global Const$RND_TYPE_D           = 3       ;  Digits (same as sf, only 0 is significant)
;
; Direction
Global Const $RND_DIR_DEFAULT = Default ; Nearest Global Const$RND_DIR_NEAREST      = 1       ;  Nearest                : 0.75 = 1
Global Const $RND_DIR_UP = 2 ; Ceiling : 0.75 = 1, -0.75 = 0 Global Const$RND_DIR_DOWN         = 3       ;  Floor                  : 0.75 = 0, -0.75 = -1
Global Const $RND_DIR_TOZERO = 4 ; Truncate : 0.75 = 0, -0.75 = 0 Global Const$RND_DIR_FROMZERO     = 5       ;  Not Truncate           : 0.75 = 1, -0.75 = -1
Global Const $RND_DIR_DITHER = 6 ; Chance depending on fraction ; ; Tie Break Method Global Const$RND_TIE_DEFAULT      = Default ;  Not Truncate
Global Const $RND_TIE_UP = 1 ; Up Global Const$RND_TIE_DOWN         = 2       ;  Down
Global Const $RND_TIE_TOZERO = 3 ; Truncate Global Const$RND_TIE_FROMZERO     = 4       ;  Not Truncate
Global Const $RND_TIE_EVEN = 5 ; To the nearest even Global Const$RND_TIE_ODD          = 6       ;  To the nearest odd
Global Const $RND_TIE_STOCHASTIC = 7 ; Even chance of up or down Global Const$RND_TIE_ALTERNATIVE  = 8       ;  First UP then DOWN
;
Global Const $RND_Pad_DEFAULT = Default ; No Global Const$RND_Pad_YES          = 1       ;  2.83 to 3dp = 2.830
Global Const $RND_Pad_NO = 0 ; 2.83 to 3dp = 2.83 ; ; Special Global Const$RND_PLACES_DEFAULT   = Default
Global       $RND_TIE_ALT_CUR = 0 ; For The alternative tie break method ; ; ================================================================================================================================ Thats probably what you wanted right? They should be included and I will update now... I'll also correct what andy said too. Mat Edit: added, corrected etc. New download link added. Should be this udf done for the time being... Edited by Mat #### Share this post ##### Link to post ##### Share on other sites Thanks. Great UDF. Very useful. [font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font] #### Share this post ##### Link to post ##### Share on other sites No problem, i'm not sure why those constants didn't make it in originally... They should have. Any one got more ideas for me to add? Mat #### Share this post ##### Link to post ##### Share on other sites hi mat, i was playing around with wus' bigint functions and made the multiplication 200 times faster. instead of mod and div and floor i just used string functions, muuuuuch faster. it makes 100! in half a scond ! try it: ;~ Author: WUS [Ben Caplins] ;~ Last Changed: 7/14/06 ;~ ;~ BigInteger datatype, modeled after the Java BigInteger Class. ;~ Work In Progress! ;~ These commented include lines are only for me, since I work off a network share ;~ #include<\\Terra\bwc1$\desktop\AutoIT\beta\include\array.au3>
;~ #include<\\Terra\bwc1$\desktop\AutoIT\beta\include\string.au3> ;~ #include<\\Terra\bwc1$\desktop\AutoIT\beta\include\math.au3>

#include<array.au3>
#include<string.au3>
#include<math.au3>

$timer = TimerInit()$mul = _Factorial(100)
$time = TimerDiff($timer) / 1000
MsgBox(48, "Test of improved multiplication", "100! = " & @CRLF & $mul & @CRLF & "Time: " &$time & " sec.")

$timer = TimerInit()$mul = Factorial(100)
$time = TimerDiff($timer) / 1000
MsgBox(48, "Test of multiplication", "The multiplication is very very slow but works." & @CRLF & "I will be working on improving its efficiency." & @CRLF & "100! = " & @CRLF & $mul & @CRLF & "Time: " &$time & " sec.")

MsgBox(48, "Test of addition", "The addition is much more efficient that the multiplication." & @CRLF & "Fib(3000) = " & @CRLF & Fib(3000))

;~ Example of how to use the bigint
Func Factorial($n) Local$a = _intToBigInteger(1)
For $i = 1 To$n
Local $b = _intToBigInteger($i)
$a = _multiplyBigIntegers($b, $a) Next Return _bigIntegerToString($a)
EndFunc   ;==>Factorial

;~ Example of how to use the bigint
Func _Factorial($n) Local$a = _intToBigInteger(1)
For $i = 1 To$n
Local $b = _intToBigInteger($i)
$a = _BigInt_Mul($b, $a) Next Return _bigIntegerToString($a)
EndFunc   ;==>_Factorial

Func Fib($n) Local$first = _intToBigInteger(0)
Local $second = _intToBigInteger(1) Local$tmp
While $n <> 0$temp = _addBigIntegers($first,$second)
$first =$second
$second =$temp
$n =$n - 1
WEnd
Return _bigIntegerToString($first); EndFunc ;==>Fib ;~ ########################################################################################## ;~ These are the functions currently needed to work with bigints. ;~ _intToBigInteger -> Returns the bigint representation of an integer. ;~ _bigIntegerToString -> Return the string representation of a bigint. ;~ _switchBigIntegerSign -> Changes the sign of the given bigint. (no return other than 1) ;~ _addBigIntegers -> Returns a bigint that is the sum of two given bigints. ;~ _multiplyBigIntegers -> Returns a bigint that is the product of two given bigints. ;~ ########################################################################################## ;~ Transforms an integer to a bigint ;~ Returns -1 if input is not an integer Func _intToBigInteger($rawInt)
If IsInt($rawInt) <> 1 Then Return -1 EndIf Local$sign
If $rawInt < 0 Then$sign = "-"
Else
$sign = "+" EndIf$rawInt = Abs($rawInt) Local$rawStr = String($rawInt) Local$strArray = StringSplit($rawStr, "") Local$bigInt[$strArray[0] + 1]$bigInt[0] = $sign Local$i
For $i = 1 To$strArray[0]
$bigInt[$strArray[0] - $i + 1] =$strArray[$i] Next _removeTrailingZeros($bigInt)
Return $bigInt EndFunc ;==>_intToBigInteger ;~ Outputs a bigint as a string ;~ Returns -1 if nonarray ;~ Returns 0 if not bigint (not 100% effective) ;~ Returns string if succeeded Func _bigIntegerToString($bigInt)
If IsArray($bigInt) = 0 Then Return -1 ElseIf$bigInt[0] <> "+"  And $bigInt[0] <> "-" Then Return 0 Else Local$output
$output =$bigInt[0]
Local $i For$i = (UBound($bigInt) - 1) To 1 Step - 1$output = $output &$bigInt[$i] Next EndIf Return$output
EndFunc   ;==>_bigIntegerToString

;~ Switches the sign of the bigint, makes subraction possible through addition
;~ Returns -1 if nonarray
;~ Returns 0 if not bigint (not 100% effective)
;~ Returns 1 if succeeded
Func _switchBigIntegerSign(ByRef $bigInt1) If IsArray($bigInt1) = 0 Then
Return -1
ElseIf $bigInt1[0] = "+" Then$bigInt1[0] = "-"
ElseIf $bigInt1[0] = "-" Then$bigInt1[0] = "+"
Else
Return 0
EndIf
Return 1
EndFunc   ;==>_switchBigIntegerSign

Func _addBigIntegers($bigInt1,$bigInt2)
_equalizeArrayLengths($bigInt1,$bigInt2)
Local $i Local$bigIntSum[UBound($bigInt1) + 1] _initializeBigInteger($bigIntSum)
If $bigInt1[0] =$bigInt2[0] Then
If $bigInt1[0] = "+" Then$bigIntSum[0] = "+"
Else
$bigIntSum[0] = "-" EndIf For$i = 1 To (UBound($bigInt1) - 1)$bigIntSum[$i] =$bigInt1[$i] +$bigInt2[$i] +$bigIntSum[$i] If$bigIntSum[$i] > 9 Then$bigIntSum[$i + 1] = 1$bigIntSum[$i] =$bigIntSum[$i] - 10 EndIf Next Else Local$temp1 = _absMax($bigInt1,$bigInt2)
Local $temp2 = _absMin($bigInt1, $bigInt2)$bigInt1 = $temp1$bigInt2 = $temp2 _equalizeArrayLengths($bigInt1, $bigInt2) If$bigInt1[0] = "+"  Then
$bigIntSum[0] = "+" Else$bigIntSum[0] = "-"
EndIf
For $i = 1 To (UBound($bigInt1) - 1)
$bigIntSum[$i] = $bigIntSum[$i] + $bigInt1[$i] - $bigInt2[$i]
If $bigIntSum[$i] < 0 Then
$bigIntSum[$i + 1] = -1
$bigIntSum[$i] = $bigIntSum + 10 EndIf Next EndIf _removeTrailingZeros($bigIntSum)
Return $bigIntSum EndFunc ;==>_addBigIntegers ;~ Multiplies two bigints Func _multiplyBigIntegers($bigInt1, $bigInt2) Local$temp = _absMax($bigInt1,$bigInt2)
Local $sign Local$bigIntProduct[UBound($temp) * 2] _initializeBigInteger($bigIntProduct)
If $bigInt1[0] =$bigInt2[0] Then
$sign = "+" ElseIf$bigInt1[0] <> $bigInt2[0] Then$sign = "-"
EndIf
Local $total = _intToBigInteger(0) For$i = 1 To (UBound($bigInt1) - 1) For$j = 1 To (UBound($bigInt2) - 1) ;~ _ArrayDisplay($bigIntProduct, "test")
$bigIntProduct[$i + $j - 1] = Mod($bigInt1[$i] *$bigInt2[$j], 10) ;~ _ArrayDisplay($bigIntProduct, "test")
$bigIntProduct[$i + $j] = _Div($bigInt1[$i] *$bigInt2[$j], 10) ;~ _ArrayDisplay($bigIntProduct, "test")
$total = _addBigIntegers($bigIntProduct, $total)$bigIntProduct = _intToBigInteger(0)
ReDim $bigIntProduct[UBound($temp) * 2]
_initializeBigInteger($bigIntProduct) Next Next$total[0] = $sign _removeTrailingZeros($total)
Return $total EndFunc ;==>_multiplyBigIntegers ;~ ########################################################################################## ;~ All functions below this point are helper functions, needed but not to be normally used. ;~ ########################################################################################## ;~ Returns an integral after division, complement to Mod func in Math.au3 ;~ Not tested for negative numbers, currently only for positive ones Func _Div($x, $y) Local$z = ($x /$y)
$z = Floor($z)
Return $z EndFunc ;==>_Div ;~ Returns the bigint that is smaller in absolute value Func _absMax($bigInt1, $bigInt2,$mode = "max")
Local $ret _removeTrailingZeros($bigInt1)
_removeTrailingZeros($bigInt2) Local$isEqual = _isBigIntegerEqual($bigInt1,$bigInt2)
If $isEqual = 1 Then$ret = $bigInt1 ElseIf UBound($bigInt1) > UBound($bigInt2) Then$ret = $bigInt1 ElseIf UBound($bigInt1) < UBound($bigInt2) Then$ret = $bigInt2 Else For$i = (UBound($bigInt1) - 1) To 1 Step - 1 If$bigInt1[$i] >$bigInt2[$i] Then If$mode = "max"  Then
$ret =$bigInt1
ElseIf $mode = "min" Then$ret = $bigInt2 EndIf ExitLoop ElseIf$bigInt1[$i] <$bigInt2[$i] Then If$mode = "max"  Then
$ret =$bigInt2
ElseIf $mode = "min" Then$ret = $bigInt1 EndIf ExitLoop EndIf Next EndIf Return$ret
EndFunc   ;==>_absMax

;~ Complementary min function
;~ Returns the bigint that is smaller in absolute value
Func _absMin($bigInt1,$bigInt2)
Return _absMax($bigInt1,$bigInt2, "min")
EndFunc   ;==>_absMin

;~ Tests to see if two bigints are equal
;~ Returns -1 if nonarrays
;~ Returns 0 if not equal
;~ Returns 1 if equal
Func _isBigIntegerEqual($bigInt1,$bigInt2)
If IsArray($bigInt1) = 0 Or IsArray($bigInt2) = 0 Then
Return -1
Else
_removeTrailingZeros($bigInt1) _removeTrailingZeros($bigInt2)
Local $isEqual = 1 Local$bigL1 = UBound($bigInt1) Local$bigL2 = UBound($bigInt2) If$bigL1 <> $bigL2 Then$isEqual = 0
ElseIf $bigL1 = 2 And$bigL2 = 2 And $bigInt1[1] = 0 And$bigInt2[1] = 0 Then
$isEqual = 1 Else Local$i
For $i = 0 To (UBound($bigInt1) - 1)
If $bigInt1[$i] = $bigInt2[$i] Then
$i =$i + 1
Else
$isEqual = 0 ExitLoop EndIf Next EndIf EndIf Return$isEqual
EndFunc   ;==>_isBigIntegerEqual

;~ removes trailing zeros from the end of a bigint
;~ Returns -1 for nonarrays
;~ Returns 1 for success
Func _removeTrailingZeros(ByRef $bigInt1) If IsArray($bigInt1) = 0 Then
Return -1
Else
Local $i = UBound($bigInt1) - 1
While $bigInt1[$i] = 0 And $i <> 1$i -= 1
WEnd
ReDim $bigInt1[$i + 1]
EndIf
Return 1
EndFunc   ;==>_removeTrailingZeros

;~ Initialize the array that holds the output of the expression
;~ Returns -1 for nonarrays
;~ Returns 1 if it succeeded
Func _initializeBigInteger(ByRef $bigInt1,$val = 0)
If IsArray($bigInt1) = 0 Then Return -1 Else$bigInt1[0] = "+"
Local $i For$i = 1 To (UBound($bigInt1) - 1)$bigInt1[$i] = 0 Next EndIf Return 1 EndFunc ;==>_initializeBigInteger ;~ Equalize the lengths of two arrays so that out of bounds errors do no occur ;~ Returns -1 for nonrays ;~ Return 0 for they are already equal ;~ Return 1 if it succeeded Func _equalizeArrayLengths(ByRef$bigInt1, ByRef $bigInt2) If IsArray($bigInt1) = 0 Or IsArray($bigInt2) = 0 Then Return -1 Else Local$arrayL1 = UBound($bigInt1) Local$arrayL2 = UBound($bigInt2) If$arrayL1 < $arrayL2 Then ReDim$bigInt1[$arrayL2] ElseIf$arrayL1 > $arrayL2 Then ReDim$bigInt2[$arrayL1] Else Return 0 EndIf EndIf Return 1 EndFunc ;==>_equalizeArrayLengths ;~ improved multiplication ;~ by jennico Func _BigInt_Mul($x, $y) Dim$result[UBound($x) + UBound($y) - 1]
$result[0] = "+" If$x[0] <> $y[0] Then$result[0] = "-"
For $i = 1 To UBound($x) - 1
For $j = 1 To UBound($y) - 1
$temp =$x[$i] *$y[$j]$result[$i +$j - 1] += StringRight($temp, 1) If StringLen($result[$i +$j - 1]) = 2 Then
$result[$i + $j] += StringLeft($result[$i +$j - 1], 1)
$result[$i + $j - 1] = StringRight($result[$i +$j - 1], 1)
EndIf
If StringLen($temp) = 2 Then$result[$i +$j] += StringLeft($temp, 1) Next Next _removeTrailingZeros($result)
;_ArrayDisplay( $result, _bigIntegerToString($x)&"*"&_bigIntegerToString($y)) Return$result
EndFunc   ;==>_BigInt_Mul

i think the whole bigint part needs a complete renovation. will see what i can do.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96

##### Share on other sites

hi mat,

i was playing around with wus' bigint functions and made the multiplication 200 times faster. instead of mod and div and floor i just used string functions, muuuuuch faster. it makes 100! in half a scond !

i think the whole bigint part needs a complete renovation. will see what i can do.

j.

I gave up on that as it had already been done, these are pretty fast, but I'll test a bit more later.

I can see a few places where it could be optimized (or at least tidied) a bit more...

I think you adapted those from Wus' originals as well. I'll give it the headers and rename the functions after school.

Mat

##### Share on other sites

I gave up on that as it had already been done, these are pretty fast, but I'll test a bit more later.

thx for the link. this is nearly impossible to find since it does not use "bigint" or "bigdec" in the post !

i was working on floating big decimals but if this has been done before... i will test it.

j.

Edit: i tested the _BigNum UDF by Eukalyptus and i am impressed. it is even faster than mine and handles bigint and float bigdec. - the coding is very advanced and seems perfect to me. WOW ! so i will give up my project.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96

##### Share on other sites

My reaction to post 2 was exactly the same

Mat

##### Share on other sites

1),MathExt\Examples\MathExt.au3(1419,24) : ERROR: fact(): undefined function.

$ret /= fact ($d - 1)

~~~~~~~~~~~~~~~~~~~~~~~^

MathExt\Examples\_BigIntAdd.au3 - 1 error(s), 0 warning(s)

2),the limit of _bigintcreate is 902233720368547800018

Edited by netegg

##### Share on other sites

Erm. That seems to be not the only problem that the current downloadable (zip) source seems to have.

>Running AU3Check (1.54.19.0)  from:C:\CODE\AutoIt3
ElseIf $nNum > 0 ~~~~~~~~~~~~~~~~^ E:\_DOWNLOAD_\_General_\_CODE_\AU3\MathExt\MathExt\MathExt.au3(1385,18) : WARNING:$n: possibly used before declaration.
For $i = 1 To$n
~~~~~~~~~~~~~~~~^
E:\_DOWNLOAD_\_General_\_CODE_\AU3\MathExt\MathExt\MathExt.au3(1386,22) : WARNING: $n: possibly used before declaration.$sRet &= __Diag($n - ~~~~~~~~~~~~~~~~~~~^ <snip> !>14:59:07 AU3Check ended.rc:2 .. ok, locally fixed. Missing function: Disable the functions _PascalGetLine() and __Diag(). These functions are not actively used in the MathExt.au3 file. (ignoring examples) Now whats that about number 902233720368547800018 being a limit. Thats way bigger than what a normal AutoIt Int-type can be. ... Erm. I see. The problem is that _bigintcreate() assume that ABS() will always return a strait formatted int. But for big int-numbers ABS() will happily return a scientific E-type notation for the number. ergo: 9223372036854775807 (input,int-type) 9.22337203685478e018 (ABS output) 902233720368547800018 (_bigintcreate() output) (Not in the mood to try to rewrite that function.) --- Edited by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions." "The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... #### Share this post ##### Link to post ##### Share on other sites I know there are better big nums out there, which is also why I haven't updated mine at all. Use Eukalyptus' as they are fast and amazing #### Share this post ##### Link to post ##### Share on other sites I didn't use any UDFs for generating large numbers, but this is a simple way to use binet's formula to generate fibonnaci sequence. I'm sure someone can make it more robust. Dim$a=0,$b=0$x = (1 + Sqrt(5))/2

$y = (1 - Sqrt(5))/2 ;~ how many you want to generate$n = 25

For $i = 1 to$n

If $i = 1 Then$a = $a +$x

$b =$b + $y EndIf If$i > 1 then

$a *=$x

$b *=$y

EndIf

$d = ($a - $b ) / Sqrt(5) ConsoleWrite($d & @LF)

Next

Edited by isiynen

##### Share on other sites

I did use Binet's formula originally to calculate the Nth Fibonacci number, like this: (1 / Sqrt (5)) * ((((1 + sqrt (5)) / 2) ^ $n) - (((1 - Sqrt (5)) / 2) ^$n))

That was a long time ago, and I had completely forgotten about Binet!

##### Share on other sites

And my apologies - I misread the top post. I remembered reading the "someone ought to show" bit and didn't realize that mean it had already been done! =D

## Create an account

Register a new account