Multiplying large numbers


Closed Thread
Results 1 to 7 of 7
  1. #1
    jhonea1's Avatar
    jhonea1 Guest

    Default Multiplying large numbers

    I think this is a quick question.

    I need to raise numbers to the fifth power. Of course, this must be done with a series of multiplications since there is no exponent support in PBP.

    The largest number possible in my equation would be 43. The max I could raise that to would be two (43*43=1849 which PBP can handle directly, 43^3=79507 which is greater than 16 bit).

    I know that I'll have to use the DIV32 function after the calculation to get my answer reduced to something reasonable. That's easy enough.

    So what I'm wondering is, is this "legal" in PBP?:

    Dummy=43*43*43*43*43
    Result=DIV32 12000


    My confusion comes in the fact the the PBP documentation only gives examples of multiplying two numbers, then using the DIV32.

    Thanks much,

    Jason

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Do you always divide by 12000?
    How small can your number be?

    Try doing your math in this order
    Answer = 43 * 43 * 43 / 2 * 43 / 30 * 43 / 200

    X var word
    Y var word
    Z var byte

    X = Z* Z
    Y = X * Z
    X = Div32 2
    Y = X * Z
    X = Div32 30
    Y = X * Z
    X = Div32 200

    For Z = 43, this gives 12250 (exact is 12250.70)

    For Z = 20 this gives 266 (exact is 266.667)

    For Z = 10 this gives 8 (exact is 8.333)

    Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  3. #3
    jhonea1's Avatar
    jhonea1 Guest


    Did you find this post helpful? Yes | No

    Default So simple that it's brilliant...

    Thanks Paul

    To answer your question, the number can be very small... less than 10. And there are actually two constants that I'll be dividing by - one is 12000 (120*100), the other is 600 (6*100).

    I was giving the abbreviated story about what I am up to. What I'm actually calculating is a Taylor series expression for sin(theta). I'll write it out for the benefit of anyone else that happens upon this post:

    sin(x)=theta -(theta^3)/3!+(theta^5)/5!...... with theta in radians

    They can also check out this link that I have been refering to:
    http://www.picbasic.co.uk/forum/show...ghlight=arcsin

    Of course, to calculate to any degree of accuracy, I have to scale numbers up (to get some significant figures) and then scale the final result down appropriately. My goal is two sig figs past the decimal point, with the last being rounded to either 0 or 5. Since that theta^5 is in there, the numbers get really difficult... especially when they are scaled up to begin with!

    Since 3!=6, and I'm playing around with scaling, you can see where the 600 comes from. Same story for the 12000.

    Anyhow, thanks so much... this will clean up my code nicely while improving accuracy.

    Jason

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink Heavy weapons ....

    Hi, jhonea1

    Depends upon the precision you need , but Have also a look there ...

    http://www.awce.com/pak1.htm

    and There :

    http://www.micromegacorp.com/pbp.html

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Sounds like a fun project and sounds like all is working ... however, as Melanie says in #19 of the link you posted, lookup tables are the fastest answer. I have used lookup tables with linear interpolation (for the added accuracy) as noted in here.

    http://www.dattalo.com/technical/theory/sinewave.html


    Have Fun,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  6. #6
    jhonea1's Avatar
    jhonea1 Guest


    Did you find this post helpful? Yes | No

    Default Thanks!!

    I just want to thank each of you for your help. I ultimately went with the Taylor series expansion method implementing Paul's suggestion to distribute the denominator across the terms.

    FYI, this project is a senior design project for mechanical engineering, which is being presented next Tuesday. Though I have been working on it all semester, the last thing to complete was to calibrate the ADC value to a height based on the geometry of the mechanism. All along, I had been planning on a lookup table. But when I wrote it out, it required more space on my microcontroller than I had available.

    That's when I started looking at Taylor series. By the time I got around to asking for your help, I was pretty well committed to that route. Given more time, I would probably use a different method, maybe even using a math coprocessor (which I admit I didn't even know existed until only a few days ago).

    Now I can breathe a big 'ol sigh of relief knowing that it's done. All I have left to do is put it together on perfboard and put it in the enclosure.

    Thanks again,

    Jason

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I'll second and third the Lookuptable stuff. Sometimes time saving AND, of course, codespace is more important than messing with math. An external EEPROM is cheap and a table made in EXCEL or else can be easily done and dump in the EEPROM when saved in the correct format. I'd never thinking to use any of math processor as now. Maybe because what i do don't require it or i can't trust anybody else than me... but that's another story.

    Good luck!
    Last edited by mister_e; - 14th April 2006 at 18:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Replies: 4
    Last Post: - 15th April 2009, 02:54
  2. handling Large Numbers
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th April 2007, 03:33
  3. store/display very large numbers (700000)
    By ttease in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th March 2007, 23:08
  4. How to display large numbers
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2006, 00:17
  5. math problems - large numbers
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th February 2004, 08:48

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts