Math statement parsed weirdly

This is a discussion on Math statement parsed weirdly within the Tech Board forums, part of the Community Boards category; Alright, so I was testing out my math parser with just a completely random statement, below: 3+3/3*2423-234/234/234-234*3-4+(4-2/4)-34 Now, when I ...

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

    Math statement parsed weirdly

    Alright, so I was testing out my math parser with just a completely random statement, below:

    3+3/3*2423-234/234/234-234*3-4+(4-2/4)-34

    Now, when I type it in to my calculator and google, I get the same result: 1,689.49573

    From Google:
    3 + ((3 / 3) * 2 423) - ((234 / 234) / 234) - (234 * 3) - 4 + (4 - (2 / 4)) - 34

    However, I don't understand why the ((234 / 234) / 234) - (234 * 3) - 4 + (4 - (2 / 4)) part is in its own parenthesis. Order of operations states that operators are done in the order that they occur in, right?

    So.....shouldn't it be
    Code:
    3  +  (3/3*2423)   -    234/234/234   -   234*3   -   4   +   (4-2/4)   -34
    Maybe I'm just confused....my math parser gives the following postfix output:
    Code:
    3.000000
    3.000000
    3.000000
    DIV
    2423.00000
    MUL
    ADD
    234.000000
    234.000000
    DIV
    234.000000
    DIV
    SUB
    234.000000
    3.000000
    MUL
    SUB
    4.000000
    SUB
    4.000000
    2.000000
    4.000000
    DIV
    SUB
    -34.000000
    ADD
    which gives me -30.5

    -edit-
    Or...wait....Ok, I just retyped it in to my calculator and am still getting the same answer, so there must be an error in my infix->postfix evaluator...*wanders off*
    Last edited by jverkoey; 06-04-2005 at 02:25 PM.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, google added redundant parentheses.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  3. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  4. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 09:06 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21