Calculations on LARGE numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frinton

    #1

    Calculations on LARGE numbers

    Hi,

    I am trying to do some calculations on large numbers (ie
    7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
    doesn't get it quite right. Its always somewhere between 10 and and 5000 out
    :(

    I have a suspition is could be down to one of the number functions I am
    using along the way but im not sure.

    Any help or guidance would be greatly appriciated.

    Thanks in advance

    Fred


  • Richard Mueller

    #2
    Re: Calculations on LARGE numbers

    Fred wrote:
    [color=blue]
    > I am trying to do some calculations on large numbers (ie
    > 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
    > doesn't get it quite right. Its always somewhere between 10 and and 5000
    > out :(
    >
    > I have a suspition is could be down to one of the number functions I am
    > using along the way but im not sure.
    >
    > Any help or guidance would be greatly appriciated.[/color]

    VB and VBScript integers are Long datatypes (32-bit) and range
    from -2,147,483,648 to 2,147,483,647, which is -2^31 to 2^31-1. Larger
    values are handled as Float datatype which is 64-bit. Your large number is
    stored as an approximation.

    --
    Richard
    Microsoft MVP Scripting and ADSI
    Hilltop Lab - http://www.rlmueller.net


    Comment

    • Egbert Nierop \(MVP for IIS\)

      #3
      Re: Calculations on LARGE numbers


      "Frinton" <fred_news@hotm ail.com> wrote in message
      news:44158bca@2 12.67.96.135...[color=blue]
      > Hi,
      >
      > I am trying to do some calculations on large numbers (ie
      > 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
      > doesn't get it quite right. Its always somewhere between 10 and and 5000
      > out :([/color]

      The best is to convert it to currency.
      dim v
      v=CCur(10)
      v=v * ccur(1030303030 30.1034)
      [color=blue]
      > I have a suspition is could be down to one of the number functions I am
      > using along the way but im not sure.[/color]

      Comment

      • Evertjan.

        #4
        Re: Calculations on LARGE numbers

        Frinton wrote on 13 mrt 2006 in microsoft.publi c.inetserver.as p.general:
        [color=blue]
        > I am trying to do some calculations on large numbers (ie
        > 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
        > doesn't get it quite right. Its always somewhere between 10 and and
        > 5000 out
        > :(
        >
        > I have a suspition is could be down to one of the number functions I
        > am using along the way but im not sure.
        >
        > Any help or guidance would be greatly appriciated.[/color]

        <http://en.wikipedia.or g/wiki/Long_division>


        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Frinton

          #5
          Re: Calculations on LARGE numbers

          Thanks for the reply

          Is there any work around to this?

          Im storing the values in SQL, is BigInt the largest exact number possible?

          Thanks

          Fred

          "Richard Mueller" <rlmueller-NOSPAM@ameritec h.NOSPAM.net> wrote in message
          news:uAuQROrRGH A.1780@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Fred wrote:
          >[color=green]
          >> I am trying to do some calculations on large numbers (ie
          >> 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
          >> doesn't get it quite right. Its always somewhere between 10 and and 5000
          >> out :(
          >>
          >> I have a suspition is could be down to one of the number functions I am
          >> using along the way but im not sure.
          >>
          >> Any help or guidance would be greatly appriciated.[/color]
          >
          > VB and VBScript integers are Long datatypes (32-bit) and range
          > from -2,147,483,648 to 2,147,483,647, which is -2^31 to 2^31-1. Larger
          > values are handled as Float datatype which is 64-bit. Your large number is
          > stored as an approximation.
          >
          > --
          > Richard
          > Microsoft MVP Scripting and ADSI
          > Hilltop Lab - http://www.rlmueller.net
          >[/color]


          Comment

          • Frinton

            #6
            Re: Calculations on LARGE numbers

            Thanks for the reply

            Im getting an overflow when I try this :(

            Fred

            "Egbert Nierop (MVP for IIS)" <egbert_nierop@ nospam.invalid> wrote in
            message news:uJdVPVrRGH A.2156@tk2msftn gp13.phx.gbl...[color=blue]
            >
            > "Frinton" <fred_news@hotm ail.com> wrote in message
            > news:44158bca@2 12.67.96.135...[color=green]
            >> Hi,
            >>
            >> I am trying to do some calculations on large numbers (ie
            >> 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
            >> doesn't get it quite right. Its always somewhere between 10 and and 5000
            >> out :([/color]
            >
            > The best is to convert it to currency.
            > dim v
            > v=CCur(10)
            > v=v * ccur(1030303030 30.1034)
            >[color=green]
            >> I have a suspition is could be down to one of the number functions I am
            >> using along the way but im not sure.[/color]
            >[/color]


            Comment

            • Frinton

              #7
              Re: Calculations on LARGE numbers

              Thanks for the reply

              Its not the calculation that is causing me the problem its the storing of
              values

              Fred

              "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
              news:Xns9785B23 58D898eejj99@19 4.109.133.242.. .[color=blue]
              > Frinton wrote on 13 mrt 2006 in microsoft.publi c.inetserver.as p.general:
              >[color=green]
              >> I am trying to do some calculations on large numbers (ie
              >> 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
              >> doesn't get it quite right. Its always somewhere between 10 and and
              >> 5000 out
              >> :(
              >>
              >> I have a suspition is could be down to one of the number functions I
              >> am using along the way but im not sure.
              >>
              >> Any help or guidance would be greatly appriciated.[/color]
              >
              > <http://en.wikipedia.or g/wiki/Long_division>
              >
              >
              > --
              > Evertjan.
              > The Netherlands.
              > (Please change the x'es to dots in my emailaddress)[/color]


              Comment

              • Tim Slattery

                #8
                Re: Calculations on LARGE numbers

                "Frinton" <fred_news@hotm ail.com> wrote:
                [color=blue]
                >Thanks for the reply
                >
                >Its not the calculation that is causing me the problem its the storing of
                >values[/color]

                In VB or VBScript there's probably no way out of this. Java (not
                JavaScript) has a BigInteger class, and there are classes available
                for C++ that can handle integers of arbitrary precision.

                Arithmetic operations in these classes would not be fast, but they
                would preserve and use the full precision.

                --
                Tim Slattery
                MS MVP(DTS)
                Slattery_T@bls. gov

                Comment

                • Jerold Schulman

                  #9
                  Re: Calculations on LARGE numbers

                  On Mon, 13 Mar 2006 15:12:09 -0000, "Frinton" <fred_news@hotm ail.com> wrote:
                  [color=blue]
                  >Hi,
                  >
                  >I am trying to do some calculations on large numbers (ie
                  >7,768,489,957, 892,578,474,792 ,094 / 12,280) and no matter what I do it
                  >doesn't get it quite right. Its always somewhere between 10 and and 5000 out
                  >:(
                  >
                  >I have a suspition is could be down to one of the number functions I am
                  >using along the way but im not sure.
                  >
                  >Any help or guidance would be greatly appriciated.
                  >
                  >Thanks in advance
                  >
                  >Fred
                  >[/color]
                  See tip 4533 » How do I perform accurate and/or complex math in a batch? 11-Dec-01
                  in the 'Tips & Tricks' at http://www.jsifaq.com

                  When I type the following at a CMD.EXE prompt:
                  for /f %i in ('domath //nologo "Round(77684899 578925784747920 94/12280)"') do @echo %i

                  I get 6.3261318875346 7E+20




                  Jerold Schulman
                  Windows Server MVP
                  JSI, Inc.


                  Comment

                  • Frinton

                    #10
                    Re: Calculations on LARGE numbers


                    "Jerold Schulman" <Jerry@jsiinc.c om> wrote in message
                    news:lvab12hhot 3fte9q60vb1qgcb vhp6h9q24@4ax.c om...[color=blue]
                    > On Mon, 13 Mar 2006 15:12:09 -0000, "Frinton" <fred_news@hotm ail.com>
                    > wrote:
                    >[color=green]
                    >>Hi,
                    >>
                    >>I am trying to do some calculations on large numbers (ie
                    >>7,768,489,957 ,892,578,474,79 2,094 / 12,280) and no matter what I do it
                    >>doesn't get it quite right. Its always somewhere between 10 and and 5000
                    >>out
                    >>:(
                    >>
                    >>I have a suspition is could be down to one of the number functions I am
                    >>using along the way but im not sure.
                    >>
                    >>Any help or guidance would be greatly appriciated.
                    >>
                    >>Thanks in advance
                    >>
                    >>Fred
                    >>[/color]
                    > See tip 4533 » How do I perform accurate and/or complex math in a batch?
                    > 11-Dec-01
                    > in the 'Tips & Tricks' at http://www.jsifaq.com
                    >
                    > When I type the following at a CMD.EXE prompt:
                    > for /f %i in ('domath //nologo "Round(77684899 578925784747920 94/12280)"')
                    > do @echo %i
                    >
                    > I get 6.3261318875346 7E+20
                    >
                    >
                    >
                    >
                    > Jerold Schulman
                    > Windows Server MVP
                    > JSI, Inc.
                    > http://www.jsiinc.com
                    > http://www.jsifaq.com[/color]


                    Comment

                    • Frinton

                      #11
                      Re: Calculations on LARGE numbers

                      Thanks for the reply

                      The trouble is when I format this result into a "readable" number (using
                      vbscripts FormatNumber function) it comes out as 632,613,188,753 ,467,000,000

                      The true answer and the one im looking for is

                      632,613,188,753 ,467,302,507

                      Regards

                      Fred





                      "Jerold Schulman" <Jerry@jsiinc.c om> wrote in message
                      news:lvab12hhot 3fte9q60vb1qgcb vhp6h9q24@4ax.c om...[color=blue]
                      > On Mon, 13 Mar 2006 15:12:09 -0000, "Frinton" <fred_news@hotm ail.com>
                      > wrote:
                      >[color=green]
                      >>Hi,
                      >>
                      >>I am trying to do some calculations on large numbers (ie
                      >>7,768,489,957 ,892,578,474,79 2,094 / 12,280) and no matter what I do it
                      >>doesn't get it quite right. Its always somewhere between 10 and and 5000
                      >>out
                      >>:(
                      >>
                      >>I have a suspition is could be down to one of the number functions I am
                      >>using along the way but im not sure.
                      >>
                      >>Any help or guidance would be greatly appriciated.
                      >>
                      >>Thanks in advance
                      >>
                      >>Fred
                      >>[/color]
                      > See tip 4533 » How do I perform accurate and/or complex math in a batch?
                      > 11-Dec-01
                      > in the 'Tips & Tricks' at http://www.jsifaq.com
                      >
                      > When I type the following at a CMD.EXE prompt:
                      > for /f %i in ('domath //nologo "Round(77684899 578925784747920 94/12280)"')
                      > do @echo %i
                      >
                      > I get 6.3261318875346 7E+20
                      >
                      >
                      >
                      >
                      > Jerold Schulman
                      > Windows Server MVP
                      > JSI, Inc.
                      > http://www.jsiinc.com
                      > http://www.jsifaq.com[/color]


                      Comment

                      • Richard Mueller

                        #12
                        Re: Calculations on LARGE numbers

                        Hi,

                        As I recall BigInt is 64-bit, but valid values range from -2^63
                        (-9,223,372,036,8 54,775,808) through 2^63-1 (9,223,372,036, 854,775,807).
                        VB.NET can handle values in this range, but VB6 and VBScript cannot. In VB6
                        I've used Currency datatypes to handle large numbers. VB6 Currency values
                        are 64-bit scaled integers (4 digits past the decimal, saved internally as
                        an integer), so the maximum value is 922,337,203,685 ,477.5807. I'm not sure
                        about VBScript currency values. I've also written my own functions to do
                        math by breaking the value up into parts, like two 31-bit values (high and
                        low parts). However, my functions multiplied numbers. I remember having to
                        code my own CInt Function because the VB function bombs out at 2^15.
                        Division seems harder.

                        Your value is 7.77 x 10^24, which would require an 84-bit register. You
                        could represent it as two 42-bit numbers. However, even the 42-bit values
                        are too large for VB6 or VBScript. That leaves you with representing the
                        value as 3 30-bit numbers.

                        x = a * 2^60 + b * 2^30 + c

                        That would be a lot of work.

                        --
                        Richard
                        Microsoft MVP Scripting and ADSI
                        Hilltop Lab - http://www.rlmueller.net

                        "Frinton" <fred_news@hotm ail.com> wrote in message
                        news:4415a442@2 12.67.96.135...[color=blue]
                        > Thanks for the reply
                        >
                        > Is there any work around to this?
                        >
                        > Im storing the values in SQL, is BigInt the largest exact number possible?
                        >
                        > Thanks
                        >
                        > Fred
                        >
                        > "Richard Mueller" <rlmueller-NOSPAM@ameritec h.NOSPAM.net> wrote in message
                        > news:uAuQROrRGH A.1780@TK2MSFTN GP12.phx.gbl...[color=green]
                        >> Fred wrote:
                        >>[color=darkred]
                        >>> I am trying to do some calculations on large numbers (ie
                        >>> 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do it
                        >>> doesn't get it quite right. Its always somewhere between 10 and and 5000
                        >>> out :(
                        >>>
                        >>> I have a suspition is could be down to one of the number functions I am
                        >>> using along the way but im not sure.
                        >>>
                        >>> Any help or guidance would be greatly appriciated.[/color]
                        >>
                        >> VB and VBScript integers are Long datatypes (32-bit) and range
                        >> from -2,147,483,648 to 2,147,483,647, which is -2^31 to 2^31-1. Larger
                        >> values are handled as Float datatype which is 64-bit. Your large number
                        >> is stored as an approximation.
                        >>
                        >> --
                        >> Richard
                        >> Microsoft MVP Scripting and ADSI
                        >> Hilltop Lab - http://www.rlmueller.net
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        • Dave Anderson

                          #13
                          Re: Calculations on LARGE numbers

                          Frinton wrote:[color=blue]
                          > I am trying to do some calculations on large numbers (ie
                          > 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter
                          > what I do it doesn't get it quite right. Its always
                          > somewhere between 10 and and 5000 out :([/color]

                          Check out the multiple-precision libraries here:




                          --
                          Dave Anderson

                          Unsolicited commercial email will be read at a cost of $500 per message. Use
                          of this email address implies consent to these terms. Please do not contact
                          me directly or ask me to contact you directly for assistance. If your
                          question is worth asking, it's worth posting.


                          Comment

                          • Evertjan.

                            #14
                            Re: Calculations on LARGE numbers

                            Frinton wrote on 13 mrt 2006 in microsoft.publi c.inetserver.as p.general:[color=blue]
                            > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                            > news:Xns9785B23 58D898eejj99@19 4.109.133.242.. .[color=green]
                            >> Frinton wrote on 13 mrt 2006 in
                            >> microsoft.publi c.inetserver.as p.general:
                            >>[color=darkred]
                            >>> I am trying to do some calculations on large numbers (ie
                            >>> 7,768,489,957,8 92,578,474,792, 094 / 12,280) and no matter what I do
                            >>> it doesn't get it quite right. Its always somewhere between 10 and
                            >>> and 5000 out
                            >>> :(
                            >>>
                            >>> I have a suspition is could be down to one of the number functions I
                            >>> am using along the way but im not sure.
                            >>>
                            >>> Any help or guidance would be greatly appriciated.[/color]
                            >>
                            >> <http://en.wikipedia.or g/wiki/Long_division>[/color][/color]

                            [please do not toppost on usenet]

                            [color=blue]
                            > Thanks for the reply
                            >
                            > Its not the calculation that is causing me the problem its the storing
                            > of values[/color]

                            That is no problem, you can store them as a string.

                            In fact, you do the long division also with string parts.

                            --
                            Evertjan.
                            The Netherlands.
                            (Please change the x'es to dots in my emailaddress)

                            Comment

                            • Richard Mueller

                              #15
                              Re: Calculations on LARGE numbers

                              I wonder if that confirms that the value was handled internally as a
                              currency, a scaled 64-bit integer. I note that I get the same answer if I
                              omit the Round function. I used the following VBScript program:

                              x= Eval("(77684899 578925784747920 94/12280)")

                              Wscript.Echo FormatNumber(x, 4)

                              --
                              Richard
                              Microsoft MVP Scripting and ADSI
                              Hilltop Lab - http://www.rlmueller.net

                              "Frinton" <fred_news@hotm ail.com> wrote in message
                              news:4415b30c@2 12.67.96.135...[color=blue]
                              > Thanks for the reply
                              >
                              > The trouble is when I format this result into a "readable" number (using
                              > vbscripts FormatNumber function) it comes out as
                              > 632,613,188,753 ,467,000,000
                              >
                              > The true answer and the one im looking for is
                              >
                              > 632,613,188,753 ,467,302,507
                              >
                              > Regards
                              >
                              > Fred
                              >
                              >
                              >
                              >
                              >
                              > "Jerold Schulman" <Jerry@jsiinc.c om> wrote in message
                              > news:lvab12hhot 3fte9q60vb1qgcb vhp6h9q24@4ax.c om...[color=green]
                              >> On Mon, 13 Mar 2006 15:12:09 -0000, "Frinton" <fred_news@hotm ail.com>
                              >> wrote:
                              >>[color=darkred]
                              >>>Hi,
                              >>>
                              >>>I am trying to do some calculations on large numbers (ie
                              >>>7,768,489,95 7,892,578,474,7 92,094 / 12,280) and no matter what I do it
                              >>>doesn't get it quite right. Its always somewhere between 10 and and 5000
                              >>>out
                              >>>:(
                              >>>
                              >>>I have a suspition is could be down to one of the number functions I am
                              >>>using along the way but im not sure.
                              >>>
                              >>>Any help or guidance would be greatly appriciated.
                              >>>
                              >>>Thanks in advance
                              >>>
                              >>>Fred
                              >>>[/color]
                              >> See tip 4533 » How do I perform accurate and/or complex math in a batch?
                              >> 11-Dec-01
                              >> in the 'Tips & Tricks' at http://www.jsifaq.com
                              >>
                              >> When I type the following at a CMD.EXE prompt:
                              >> for /f %i in ('domath //nologo "Round(77684899 578925784747920 94/12280)"')
                              >> do @echo %i
                              >>
                              >> I get 6.3261318875346 7E+20
                              >>
                              >>
                              >>
                              >>
                              >> Jerold Schulman
                              >> Windows Server MVP
                              >> JSI, Inc.
                              >> http://www.jsiinc.com
                              >> http://www.jsifaq.com[/color]
                              >
                              >[/color]


                              Comment

                              Working...