Math overflow?


Closed Thread
Results 1 to 3 of 3

Thread: Math overflow?

Hybrid View

  1. #1
    egberttheone's Avatar
    egberttheone Guest

    Exclamation Math overflow?

    For some project I need to do some calculations, since debugging for this project is very hard because I have not really an output device on this project. I would like to know if this calculation would work smoothly:

    Code:
    Temp2 var byte
    Temp3 var word
    
    Temp3 = (MasterVolume * 128) / 100
    Temp2 = Temp3 + ((Temp3 * (TrimLeft * 10)) / 500)
    Mastervolume and trimleft having a max. value of 100

    is this the right way for this calculation ? i already know that the result will not be 100% but this is not a problem.

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Yes, it will work fine for Temp3,

    But tempt2 will be approx 12 million. You will have to use a double on this. Melabs has a FP up to 32 bits...

    http://www.melabs.com/resources/fp.htm

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Or, you could just use DIV32. And, make sure Temp2 is a WORD.
    Code:
    Temp2 var word
    Temp3 var word
    
    Temp3 = (MasterVolume * 128) / 100
    Temp2 = TrimLeft * 10
    Temp2 = Temp2 * Temp3 
    Temp2 = DIV32 500
    Temp2 = Temp2 + Temp3
    HTH,
       Darrel

Similar Threads

  1. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 04:20
  2. Pulsin Math question
    By ruijc in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2008, 16:15
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  4. Overflow bit?
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 14th October 2006, 01:03
  5. not quite understanding the MATH function
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th January 2006, 20:20

Members who have read this thread : 0

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