Results 1 to 11 of 11

Thread: BIG numbers

  1. #1
    sql_lall
    Guest

    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.

  2. #2
    Hyperactive Member DavidHooper's Avatar
    Join Date
    Apr 2001
    Posts
    357
    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.

  3. #3
    wossname
    Guest
    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) ?

  4. #4
    sql_lall
    Guest

    Question 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.

  5. #5
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    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.

  6. #6
    sql_lall
    Guest

    Post 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

  7. #7

  8. #8
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    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.

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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:
    1. For x = 1 To 10
    2.     If x > y Then
    3.         Exit For
    4.     Else
    5.         y = y \ Sqr(x)
    6.     End If
    7. Next x
    Harry.

    "From one thing, know ten thousand things."

  10. #10
    Hyperactive Member thinktank2's Avatar
    Join Date
    Nov 2001
    Location
    Arctic
    Posts
    272
    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.

  11. #11
    sql_lall
    Guest

    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
  •  



Click Here to Expand Forum to Full Width