|
-
Jan 19th, 2002, 03:41 AM
#1
BIG numbers
Ok, currently I have made a program that can add 100 digit positive integers, and making one that can multipy 50 digit positive integers. Just wondering if people want the programs and/or if anyone can come up with a way to find out the bigger of two 100 digit positive integers. (I currently treat the numbers as strings and work it out as a human would by hand)
I think i know a way, but wondering if there is a different way.
-
Jan 19th, 2002, 04:55 AM
#2
Hyperactive Member
Yep, I'd be interested and happy to test out code etc.
You should really investigate storing the numbers in byte arrays instead of strings. Byte arrays are faster, easier to implement and make carries in arithmetic more straightforward.
There are 10 types of people in the world - those that understand binary, and those that don't.
-
Jan 19th, 2002, 12:53 PM
#3
What is the difference in speed between your program and an equivalent program that uses the Double Data Type (which can handle approx 309 digit numbers) ?
-
Jan 19th, 2002, 08:09 PM
#4
Double Data type numbers
HOw can they do that?? I though that they could only go to a certain number of decimal places.
Anyway, I will post the code tomorrow or the next day.
Also, there isn't a limit to how many digits each number is, they could both be 1 million digits, but any more than 100 digits looks won't fit nicely onto a screen. Perhaps I will make it read from a .txt file.
-
Jan 19th, 2002, 10:46 PM
#5
Frenzied Member
Wossname: Doubles can handle numbers representing values larger than 10^300, but the precision is limited to about 15 decimal digits.
Extra precision arithmetic can provide more precison than a Double, although it is rarely required. Most practical problems can be managed with 15 digit precision, although somethimes a little numerical analysis is required to avoid loss of precision.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Jan 21st, 2002, 02:10 AM
#6
Here's the code.
REM **Put in the Form1 code
REM **This can handle any size numbers.
REM **You must have three textboxes (text1, text2 and text3)
REM ** When you add, text1 and text2 will be added and the answer will be in text3
REM **Also two Command buttons are needed (Command1 and Command2)
REM **Command1 = add button, command2 = clears all text boxes
Private Sub Command1_Click()
str1 = LTrim(RTrim((Text1.Text)))
str2 = LTrim(RTrim((Text2.Text)))
If Len(str2) > Len(str1) Then
tempstr = str2
str2 = str1
str1 = tempstr
End If
'If Len(str1) > 100 Then
'MsgBox ("Too Big!!!")
'GoTo bigger
'End If
first = str1
second = str2
' *********************
len1 = Len(first)
len2 = Len(second)
temp2 = len1 - len2
ReDim Digits(2, len1 + 1)
ReDim add(len1 + 1)
Digits(1, len1 + 1) = 0
Digits(2, len1 + 1) = 0
For a = 1 To len1
Digits(1, a) = Val(Mid$(first, a, 1))
Next a
For a = 1 To len2
Digits(2, a + temp2) = Val(Mid$(second, a, 1))
Next a
For adds = len1 + 1 To 2 Step -1
add(adds) = (Digits(1, adds - 1) + Digits(2, adds - 1) + buff) Mod 10
buff = Int((Digits(1, adds - 1) + Digits(2, adds - 1) + buff) / 10)
Next adds
If buff = 1 Then add(1) = 1
' *********************
Text3.Text = ""
For la = 1 To len1 + 1
If Not (la = 1 And add(la) = 0) Then Text3.Text = Text3.Text + LTrim(RTrim(Str(add(la))))
Next la
bigger:
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
REM ***Put in Module1
Public add(), carry() As Integer
Public Digits() As Integer
Public len1, len2, temp1, temp2 As Integer
Public str1, str2, tempstr, first, second As String
-
Jan 21st, 2002, 10:36 AM
#7
You must not know about:
[vbcode]
Put your code here
[/vbcode]
yet.
-
Jan 21st, 2002, 10:49 AM
#8
Frenzied Member
NotLKH: What is the difference between vbcode inside brackets and code inside brackets?
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Jan 21st, 2002, 11:24 AM
#9
Frenzied Member
The [ vbcode ] tags probably do colour highlighting.... lets try it out:
Code:
For x = 1 To 10
If x > y Then
Exit For
Else
y = y \ Sqr(x)
End If
Next x
VB Code:
For x = 1 To 10 If x > y Then Exit For Else y = y \ Sqr(x) End If Next x
Harry.
"From one thing, know ten thousand things."
-
Jan 21st, 2002, 12:32 PM
#10
Hyperactive Member
Originally posted by Guv
NotLKH: What is the difference between vbcode inside brackets and code inside brackets?
code is for Monospace font with space characters preserved intact. You can use it to post soure code in any language(HTML,Javascript,vbscript....).
Vb code is Code++ with Syntax Highlighting but it doesn't make sense if your code is not VB.
-
Jan 22nd, 2002, 04:00 AM
#11
TY
THankyou, I will keep that in mind.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|