How do I make formulas with exponenets?

How do I make formulas with exponenets?

I want to make this into a formula, how do I go about it?

W = 13.12 + 0.6215t - 11.37v^016 + 0.3965tv^0.016



Also, I tried doing this to try out the exponent but unfortunately it does not give me the correct answer for an exponent, why is that? What does the "^" do in c++?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int c = 2^2;
	
	cout << c;
	
}
> What does the "^" do in c++?

The bit-wise exclusive or operator: https://msdn.microsoft.com/en-us/library/3akey979.aspx


> I want to make this into a formula, how do I go about it?

See std::pow() http://en.cppreference.com/w/cpp/numeric/math/pow

What does the "^" do in c++?
It is the exclusive or operator. See:

http://www.cplusplus.com/doc/tutorial/operators/


To get the power of a number you need the function pow(...):

http://www.cplusplus.com/reference/cmath/pow/?kw=pow
pow can do fractional exponents, so it can also do sqrt etc, (pow(x, 0.5) for example). Because of this, its a bit slower than you might expect. Consider just doing X*X etc for very small powers (often code needs no more than squares). Its powerful (hah) but not always optimal.

You can look up the bitwise operators... ( |, &, ^, etc). Im right there to say that ^ should have been power. They ran out of symbols.

Last edited on
Strongly favour std::sqrt() for finding the square root.
http://en.cppreference.com/w/cpp/numeric/math/sqrt

May also be of interest:
std::hypot() http://en.cppreference.com/w/cpp/numeric/math/hypot
std::cbrt() http://en.cppreference.com/w/cpp/numeric/math/cbrt
Topic archived. No new replies allowed.