# Making a comparison between large numbers

## Recommended Posts

Is their anyway that I can compare 2 large integers with 33 digits? It seem that AutoIt treats small differences as equal probably because it uses a scientific notation which chops off a lot of numbers. is their anyway around this?

Example I want AutoIt to recognize the difference between

16777215167772081677721513668432

And

16777215167772081473348016312512

Is it possible?

##### Share on other sites

Only if you represent the numbers through arrays so that every digit would be an array element..and then simulate every operation you need done..That's how I would have done it in a "classical" programming language..I have no idea if AutoIt has any special functions to handle such numbers, or anything of the sort..It *CAN* be done, but it's a real hassle to multiply 2 such numbers..the addition function is simple, but say if you have "numbers"(digit arrays) A and B and want A*B, you would need a function to multiply the 2 arrays which can't be simulated by repetitive addition, because the for accepts only integer vars..anyway..it's a complicated matter..hope I didn't rant on the wrong subject too much..But I thought this is what you were actually asking..

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

Only if you represent the numbers through arrays so that every digit would be an array element..and then simulate every operation you need done..That's how I would have done it in a "classical" programming language..I have no idea if AutoIt has any special functions to handle such numbers, or anything of the sort..It *CAN* be done, but it's a real hassle to multiply 2 such numbers..the addition function is simple, but say if you have "numbers"(digit arrays) A and B and want A*B, you would need a function to multiply the 2 arrays which can't be simulated by repetitive addition, because the for accepts only integer vars..anyway..it's a complicated matter..hope I didn't rant on the wrong subject too much..But I thought this is what you were actually asking..

<{POST_SNAPBACK}>

So then what is the maximum number of digits that I can use? If necessary I can break up the larger numbers.

##### Share on other sites

You can do almost anything with AutoIt.

It depends in what way you want to compare the 2 numbers. There are many different choices... A-B, thats a difference. You might want to compare each digit individually.

Example

```A = 16777215167772081677721513668432
B = 16777215167772081473348016312512

Comparison = 0000000000000000020427503356120```

Digits are the same in both numbers represented by a 0, and ones that arnt I minused the smallest number out of the digits.

As I said before it depends by what means you want to compare them.

qq

##### Share on other sites

You can do almost anything with AutoIt.

It depends in what way you want to compare the 2 numbers. There are many different choices... A-B, thats a difference. You might want to compare each digit individually.

Example

```A = 16777215167772081677721513668432
B = 16777215167772081473348016312512

Comparison = 0000000000000000020427503356120```

Digits are the same in both numbers represented by a 0, and ones that arnt I minused the smallest number out of the digits.

As I said before it depends by what means you want to compare them.

<{POST_SNAPBACK}>

I've done A-B but Auto-it did not notice the difference. When I subtracted one from the other all it returns is 0. All I need is a method that shows a difference for an If-Then statement.

##### Share on other sites

I've done A-B but Auto-it did not notice the difference. When I subtracted one from the other all it returns is 0. All I need is a method that shows a difference for an If-Then statement.

<{POST_SNAPBACK}>

```\$a = 16777215167772081677721513668432
\$b = 16777215167772081473348016312512
\$c = \$a - \$b
Msgbox(0,"test",\$c)```

Works for me.

And.

```\$a = 16777215167772081677721513668432
\$b = 16777215167772081473348016312512

If \$a = \$b Then
Msgbox(0,"Same","The 2 numbers are the same!")
Else
Msgbox(0,"Diff","The 2 numbers are different!" & @CRLF & "Difference: " & \$a - \$b)
EndIf```
Edited by Burrup

qq

##### Share on other sites

```\$a = 16777215167772081677721513668432
\$b = 16777215167772081473348016312512
\$c = \$a - \$b
Msgbox(0,"test",\$c)```

Works for me.

And.

```\$a = 16777215167772081677721513668432
\$b = 16777215167772081473348016312512

If \$a = \$b Then
Msgbox(0,"Same","The 2 numbers are the same!")
Else
Msgbox(0,"Diff","The 2 numbers are different!" & @CRLF & "Difference: " & \$a - \$b)
EndIf```

<{POST_SNAPBACK}>

Why does the addition of the array change things?

\$a = 16777215167772081677721513668432

\$b = 16777215167772081473348016312512

Dim \$c[2]

\$c[0] = \$a

\$c[1] = \$b

If \$a = \$b Then

Msgbox(0,"Same","The 2 numbers are the same!(a andb)")

Else

Msgbox(0,"Diff","The 2 numbers are different!")

EndIf

If \$c[0] = \$c[1] Then

Msgbox(0,"Same","The 2 numbers are the same!c[]")

Else

Msgbox(0,"Diff","The 2 numbers are different!")

EndIf

Edited by Coolsurfer

##### Share on other sites

It doesn't for me... Both return "The 2 numbers are different!", are you sure you have a latest BETA or 3.1.1 stable version.

qq

##### Share on other sites

Why does the addition of the array change things?

\$a = 16777215167772081677721513668432

\$b = 16777215167772081473348016312512

Dim \$c[2]

\$c[0] = \$a

\$c[1] = \$b

If \$a = \$b Then

Â  Msgbox(0,"Same","The 2 numbers are the same!(a andb)")

Else

Â  Msgbox(0,"Diff","The 2 numbers are different!")

EndIf

If \$c[0] = \$c[1] Then

Â  Msgbox(0,"Same","The 2 numbers are the same!c[]")

Else

Â  Msgbox(0,"Diff","The 2 numbers are different!")

EndIf

<{POST_SNAPBACK}>

You didn't quite get me..you declare yourself an array a2..and each element is a digit of a..so a[1]=1, a[2]=6 aso ... a[32]=3 a[33]=2..and then you would build a funct. that would substract b2, array built using the same method from a2..If it's only addition and that substraction, it's pretty easy..

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

It doesn't for me... Both return "The 2 numbers are different!", are you sure you have a latest BETA or 3.1.1 stable version.

<{POST_SNAPBACK}>

version is old, so I'll get the new one and let you know.

##### Share on other sites

Ok..that was REALLY vague..sorry..I'm really tired..

a2=123456

b2=789012

;Substract b2 from a2 digit by digit, starting from the end..

That's easy to implement..

and a2 and b2 are arrays..

Edited by VicTT

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

It worked correctly. 1st message box, "The 2 numbers are the same!", 2nd, "The 2 numbers are different!". Tested with BETA 3.1.1.18

qq

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...