Mathematical Precedence


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    Hi keithdoxey,

    If you enter "120-6+9+36" into an excel cell without the parenthesis, you will get 159 instead of 69.

    Did you check?
    ----------------
    My brain hurts !!!!

    Its fairly irrelevant now as I have just proved that my PIC code is not working right although I cant see how I broke it!

    I cant see how I am getting the wrong value for the Weekday as a test routing that just generates the values gives correct result. Maybe it is a problem when I write to the RTC chip. Will try that next.
    Keith

    www.diyha.co.uk
    www.kat5.tv

  2. #2
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    When you get back to the step, post the exact expression you are concerned with so we can play.

    The order of operation can be crucial when performing limited range integer only calculations. Concider a simple expression such a A*B/C.

    At first it looks like order doesn’t matter here. But it does. Let B=7, A=C=2, then we have: 2*7/2 Is this 6 or 7?

    How did I get 6? I worked it right to left. 7/2=3 (3?? Oh yeah, integer only!), and 2x3=6.

    Depending on the magnitude of the numbers you may want to multiply first (as to keep precision) or to divide first (to prevent an overflow).

  3. #3
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ErnieM
    When you get back to the step, post the exact expression you are concerned with so we can play.
    Hi Ernie,

    It doesnt matter now. I thought there was a problem with a calculation that Melanie put in her RTC code but it turns out that I broke it

    I had "modified" some code prior to the calculation that I thought was giving an error but it was a case of "Garbage In, Garbage Out".

    The changes I had made to the code resulted in it being given BCD values rather than Decimal ones which it why it was OK on early days in the month and for the first part of a year but was giving problems with numbers higher than 9.

    Thanks
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. Mathematical calculation
    By amindzo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 27th October 2013, 00:07
  2. Mathematical problem
    By iugmoh in forum General
    Replies: 2
    Last Post: - 25th January 2008, 18:24

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