not quite understanding the MATH function


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    It will help if you post the part of your program where you declare all of the variables you are using, and also post the errors you are getting.

    Its not a good idea to use 0.5*(etc etc). You will be better off shifting 1 place to the right like this (etc etc)>>1.

    Also, if you are declaring variables as bytes you have to make sure you cant possibly end up with a value higher than 255 in any of your calculations.
    Last edited by Kamikaze47; - 16th January 2006 at 17:16.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > Its not a good idea to use 0.5*(etc etc).

    Actually, it's not a good idea to use any numbers with Decimal places... Why? Because PICBasic ONLY works with INTEGERS.

  3. #3
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    Learning in the process. Thanks for the heads up. I think that is were I was getting the mistake or the headache.

    I have attached the whole prgram that I am trying to use. The problem that I am having starts with labels LIMITSA. I think that the whole problem that I am getting is with that .5

    The other thing is that I am using a linear equation to solve for a result in the range of 1 to 2. With the label PROGRAM2 you can see that I have 510 with part of the equation, but it should all come back and relate to that range of 1-2. will this be a problem.

    The equations that I would like to base all of this off of is the second line to label PROGRAM1 and PROGRAM2. The difference between the two is that of the slope.
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    im sorry to say there are quite a few problems with your program.

    all 11 lines with decimal numbers are invalid. This includes the lines where you multiply by 0.5 and the lines which include 1.5. As Melanie said, PBP only deals with integers.

    in one of the lines you divide something by negative 255, however PBP does not support signed variables.

    you may want to make some more variables words instead of bytes becuase it looks like some of your variables may overflow

  5. #5
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    ok. I make sense to what you are saying. Looking at what the manual has and to what you are saying. I made some correction since the last time we have talk.

    Still working out some of the kinks that are in the program so.

    I wrote out everything long hand and the other thing that I have to refresh myself up on is that >>1 = .5 ordeal. Been too long since I last seen that.

    Will work more into making sense with what you are saying and learning about that difference. Thanks
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    yes, variable>>1 is the same as variable/2. >> is a bnary shift. so if a=8 for example, thats 00001000 in binary. when u shift it all 1 place to the right (>>1), you get 00000100 which is 4 (i.e. you have halved the value).

    I notice you have some (1/2)'s in your modified program, but im afraid that wont work either. PBP will calculate that 1/2 (or 1>>1) as 0. 1 is represented in binary as 00000001 and if you shift that right 1 place you get 00000000.

    Remember that time[lmt] is an allways going to be an integer (whole number). Therefore there is no point in checking if it is equal to 1.5 since it will never be 1.5.
    Last edited by Kamikaze47; - 17th January 2006 at 06:09.

  7. #7
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    Making sense. Been too long since i last did all of this. ok 1 is set in place for 0001B, 01Q, 1, and 01H then how does the half come. I can follow the counting that takes place when 0-F in Hex or 0-9 in decimal, butthe halves. I think it is safe to ask for reference to fractional literature. I would like to further my knowledge in such.

    It is not quite as simple when it come to the basic math as we know of it as (what we learned in grade school) and for the following of fractions using controllers, well... Thanks I would have to say. Just show how far out off the loop I fall.


    "yes, variable>>1 is the same as variable/2. >> is a bnary shift. so if a=8 for example, thats 00001000 in binary. when u shift it all 1 place to the right (>>1), you get 00000100 which is 4 (i.e. you have halved the value)."

    so if I put >>2 would that be /4 (division by four). The shift right by 2 places. Trying to make sense.



    The second question is the label PROGRAM2. I have an equation that has a negative value in the denominator. In paper math it should cancel out to a positive number. You had mention something earlier about this, would I have to change the equation so that there is no negative in the denominator or is there some way to work with the equation as is?



    The third question is that I have the 1.5 would this fall to you shift comment. That it is more appropriate to utilize (1 + (>>1)) rather than to what I have.

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 03:01
  2. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 04:20
  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. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05

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