Smith
Smith

Reputation: 407

error 2296: '^' : illegal , left operand has type 'double'

Part of my code:

double function (double x)
{
   f = x^5-3*x^4+3*x^3-2*x^2-5;
   return f;
}

Problem: I am getting following errors for this part of the code:

My Goal: I am writing a code to find the roots of the following polynomial in C++, Visual Studio 2012: enter image description here

I am not sure how to solve this error since I am learning C++ and this is my first time I encountered this error. There are only two aforementioned errors; rest of my code is error-free. Your help will be much appreciated. Thank you!

Upvotes: 1

Views: 4485

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37202

The ^ operator in C/C++ is not an exponent operator (by default) - it's a bitwise XOR operator, and doesn't work on doubles.

Instead, use the pow function.

Upvotes: 5

Related Questions