exponential operator

This is a discussion on exponential operator within the C++ Programming forums, part of the General Programming Boards category; I am having problems with precedence. I am looking at a study guide and it says that: 2^4/2*3 is equal ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    18

    exponential operator

    I am having problems with precedence. I am looking at a study guide and it says that:

    2^4/2*3

    is equal to 4 (where ^ is the exponential operator). And also,

    4^3/2/3/2

    is equal to 4 (where ^ is the exponential operator).

    I can't see how they get 4 and also I can't find any information on the exponential operator (putting it into search engines and in my book). I think it may have something to do with the numbers being of type int so that when you divide two ints and get a decimal value, it rounds down.

    I don't know if I am right and I can't see how they get 4 four the answer to both of these expressions. Help me or at least let me know where I can read about the exponential operator

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    there isn't a '^' exponential operator in C++, but there is an '^' as the XOR operator. SInce XOR has lower precendence than * and /, XOR is evaluated last. So the equation:

    2^4/2*3 == 2^((4/2)*3) when considering precedence.

    which simplifies to

    2 ^ 6, which equals 4

    Same thing for the next equation

    4 ^ 3/2/3/2 = 4^0 = 4

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53
    #include <math.h>

    use the pow function it returns a double;

    double pow(double base, double exp);

    double ans = 0.0;

    2^4/2*3 //try this ans = pow(2,4)/2*3;


    is equal to 4 (where ^ is the exponential operator). And also,

    4^3/2/3/2 //try this ans = pow(4,3)/2/3/2;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  4. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 01:55 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

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