Sign in to follow this  
Followers 0
jiglei

Huge numbers problem

3 posts in this topic

#1 ·  Posted (edited)

Hey, I'm building a probabilities and counting calculator (thats how we call in portugal, directly translated, dunno about other countries), and to calculate the combination of various numbers, it results a division of a huge number by another huge number. Here comes the weird thing, when in my middle algorithm tests found out that all I learnt in math is wrong. In fact you can get a negative number by multiplying 2 positives (I'm obviously being sarcastic). For instances:

70982727012145168384*2=-2

I was like: "What the hell?"

I did some search and found out that's something related to variable or autoit limits, I couldn't understand it very well, and would appreciate if someone could explain it in a clear way :graduated:

Also, found out that BigNum UDF seems to be a good work around. But, my functions will not always need to use that... So, I need to know at which number do I need to use the BigNum UDF, or, if I can also calculate small numbers with it.

I was thinking in adding a simple condition in my calculating algorithms/functions/w-e:

If $Number > $Maximum Then
;Use BigNum UDF
Else
;Simple autoit math, i.e: $a*$b
Endif

Is this reliable? cause if the numbers are looking weird it will mess up all the calculations and give wrong results.

I don't mind if it used cientific notation, actualy, I was hoping it would use it, that way it would simpler imo.

Here's my script, sorry, it is in portuguese, if there's any question about it just ask.

Feel free to use any code in it for any porpuses.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=calculadora.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $State1 = "none",$Input4

#region ### START Koda GUI section ### Form=C:\Users\David\Documents\AutoIT\Calculadora probabilidades\Form1.kxf
$Form1 = GUICreate("Calculadora Mike The Fox - Versão Probabilidades", 529, 541, 192, 114)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("Calcular Arranjos, Permutações, Combinações.", 0, 8, 521, 201)
$Radio1 = GUICtrlCreateRadio("Combinações", 16, 40, 89, 17)
$Radio2 = GUICtrlCreateRadio("Arranjos sem repetição", 16, 64, 129, 17)
$Radio3 = GUICtrlCreateRadio("Arranjos com repetição", 16, 88, 129, 17)
$Radio4 = GUICtrlCreateRadio("Permutações", 16, 112, 113, 17)
$Label1 = GUICtrlCreateLabel("Resultado:", 8, 176, 104, 26)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$Label2 = GUICtrlCreateLabel("0", 125, 176, 200, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
$Button1 = GUICtrlCreateButton("Copiar resultado", 400, 184, 83, 17, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Calcular", 336, 152, 75, 17, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Triângulo de Pascal", 0, 216, 521, 145)
$Radio5 = GUICtrlCreateRadio("Criar as", 8, 240, 57, 17)
$Input1 = GUICtrlCreateInput("n", 66, 238, 32, 21)
$Label3 = GUICtrlCreateLabel("primeiras linhas do triângulo", 112, 240, 133, 17)
$Radio6 = GUICtrlCreateRadio("Criar linha específica:", 8, 264, 129, 17)
$Input2 = GUICtrlCreateInput("n", 137, 260, 32, 21)
$Radio7 = GUICtrlCreateRadio("Criar as linhas:", 8, 288, 89, 17)
$Input3 = GUICtrlCreateInput("", 104, 286, 193, 21)
$Label4 = GUICtrlCreateLabel("(separe o número das linhas com vírgulas)", 304, 288, 203, 17)
$Button2 = GUICtrlCreateButton("Criar Triângulo!", 227, 320, 75, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Binómio de Newton", 0, 368, 521, 161)
$Radio8 = GUICtrlCreateRadio("Calcular o resultado de um Binómio", 8, 392, 193, 17)
$Radio9 = GUICtrlCreateRadio("Desenvolver um binómio", 8, 416, 145, 17)
$Radio10 = GUICtrlCreateRadio("Calcular um termo", 8, 440, 113, 17)
$Radio11 = GUICtrlCreateRadio("Calcular o resultado de um termo", 8, 464, 177, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Radio1
            Switch $State1
                Case "None"
                    $State1 = "Combinações"
                    $Label5 = GUICtrlCreateLabel("C", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Arranjos sem repetição"
                    $State1 = "Combinações"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("C", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Arranjos com repetição"
                    $State1 = "Combinações"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("C", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    Case "Permutações"
                    $State1 = "Combinações"
                    GUICtrlDelete($Input4)
                    $Label5 = GUICtrlCreateLabel("C", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
            EndSwitch

        Case $Radio2
            Switch $State1
                Case "None"
                    $State1 = "Arranjos sem repetição"
                    $Label5 = GUICtrlCreateLabel("A", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Combinações"
                    $State1 = "Arranjos sem repetição"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("A", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")

                Case "Arranjos com repetição"
                    $State1 = "Arranjos sem repetição"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("A", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    Case "Permutações"
                    $State1 = "Arranjos sem repetição"
                    GUICtrlDelete($Input4)
                    $Label5 = GUICtrlCreateLabel("A", 344, 48, 44, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
            EndSwitch
        Case $Radio3
            Switch $State1
                Case "None"
                    $State1 = "Arranjos com repetição"
                    $Label5 = GUICtrlCreateLabel("A'", 344, 48, 55, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Arranjos sem repetição"
                    $State1 = "Arranjos com repetição"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("A'", 344, 48, 55, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Combinações"
                    $State1 = "Arranjos com repetição"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Label5 = GUICtrlCreateLabel("A'", 344, 48, 55, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                Case "Permutações"
                    $State1 = "Arranjos com repetição"
                    GUICtrlDelete($Input4)
                    $Label5 = GUICtrlCreateLabel("A'", 344, 48, 55, 72)
                    GUICtrlSetFont(-1, 45, 400, 2, "Times New Roman")
                    $Input4 = GUICtrlCreateInput("n", 334, 33, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
                    $Input5 = GUICtrlCreateInput("p", 396, 103, 57, 27, -1, 0)
                    GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
            EndSwitch
        Case $Radio4
            Switch $State1
                Case "none"
                    $State1 = "Permutações"
                    $Input4 = GUICtrlCreateInput("n!", 304, 48, 185, 76, BitOR($ES_CENTER, $ES_AUTOHSCROLL), 0)
                    GUICtrlSetFont(-1, 45, 800, 0, "Times New Roman")
                Case Else
                    $State1 = "Permutações"
                    GUICtrlDelete($Label5)
                    GUICtrlDelete($Input4)
                    GUICtrlDelete($Input5)
                    $Input4 = GUICtrlCreateInput("n!", 304, 48, 185, 76, BitOR($ES_CENTER, $ES_AUTOHSCROLL), 0)
                    GUICtrlSetFont(-1, 45, 800, 0, "Times New Roman")
                EndSwitch
            Case $Input4
                If $State1="Permutações" And StringInStr(GUICtrlRead($input4),"!")=0 Then GUICtrlSetData($input4,GUICtrlRead($input4)& "!")
            Case $Button3
Switch $State1
    Case "Combinações"

GUICtrlSetData($label2,_Combinacoes(Execute(GUICtrlRead($input4)),Execute(GUICtrlRead($input5))))


    EndSwitch
    EndSwitch
WEnd

Func _Combinacoes($n,$p)
    Return _Arranjos_simp($n,$p)/_Factorial($p)
EndFunc
Func _Arranjos_simp($n,$p)
    Local $n2=$n
    If $p=0 and $n>=0 then Return 1
    For $i=1 to $p-1
        $n2=Execute($n2*($n-$i))
    Next
        Return $n2
EndFunc
Func _Factorial($x)
    Local $x2=$x,$i=1
    If $x=1 or $x=0 Then Return 1
    $x2=$x
    $i=1
    Do
        $x2=$x2*($x-$i)
        $i+=1
    Until $i=$x-1
    Return $x2
    EndFunc

I'm sorry if the code feels messy, but I don't think you actualy need to look at it since all I need is to find a good solution to calculate any number...

By the way the purpuse of this program is merely self-educative, and even to learn more of autoit. Guess im progressing in that lol.

Thank you for your time.

Edited by jiglei

Share this post


Link to post
Share on other sites



I did some search and found out that's something related to variable or autoit limits, I couldn't understand it very well, and would appreciate if someone could explain it in a clear way

Erm. Yea, basic computer stuff.

Maybe this page will help. http://www.wordiq.com/definition/Integer_(computer_science)

BigNum stuff ... Think its better you digest that computer-integer part first before continuing further.

O yea ... 15. What are the current technical limits of AutoIt v3?


"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

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