3 Replies - 347 Views - Last Post: 13 October 2012 - 12:00 AM Rate Topic: -----

#1 karatekungfuchicken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-September 12

receiving an error using '^'

Posted 12 October 2012 - 04:29 PM

recieving [Error] invalid operands of types 'double' and 'int' to binary 'operator^'

for the following code

all variables are declared as doubles.

yVertex = (aCoeff * xVertex ^ 2) + (bCoeff * xVertex) + cCoeff;


Are there any specific rules for using '^'???
Is This A Good Question/Topic? 0
  • +

Replies To: receiving an error using '^'

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4281
  • View blog
  • Posts: 13,444
  • Joined: 25-December 09

Re: receiving an error using '^'

Posted 12 October 2012 - 04:34 PM

Do you know that the operator^ is the exclusive or operator, not the exponentiation operator? For your example I recommend just using multiplication ( X * X ).

Jim
Was This Post Helpful? 1
  • +
  • -

#3 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1112
  • View blog
  • Posts: 4,619
  • Joined: 09-June 09

Re: receiving an error using '^'

Posted 12 October 2012 - 05:51 PM

Bit wise operators, like xor (^), are meant for integers types. Using them for floating point variables doesn't make sense because they contain three different sections in their binary representation.
Was This Post Helpful? 1
  • +
  • -

#4 Coding Mash  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 26
  • Joined: 29-September 12

Re: receiving an error using '^'

Posted 13 October 2012 - 12:00 AM

(^) is Exclusive OR (XOR) operator.
If you want to take power of something, make use of power function in math library.

#include<math.h>
int a = 4 ;
cout << pow(a, 2) ;



It would print 16, 4 * 4.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1