double "^" operations ???...

A

adam.balgach

Greetings all,

I am having a hard time performing exponential operations on doubles.
My code looks like

public double getExpon(double a, double b) {
double ans = a ^ b;
return(ans);
}

and I am getting the compiler error:

operator ^ cannot be applied to double,double
double ans = a^b;


Does anyone know why? I am totally bewildered.
 
A

adam.balgach

Never mind, I forgot you have to use Math.pow(a,b)

and not a^b [bitwise OR operation?]
 
A

Adam Maass

Greetings all,

I am having a hard time performing exponential operations on doubles.
My code looks like

public double getExpon(double a, double b) {
double ans = a ^ b;
return(ans);
}

and I am getting the compiler error:

operator ^ cannot be applied to double,double
double ans = a^b;


Does anyone know why? I am totally bewildered.

^ isn't exponentiation in Java; it's (integer) XOR.

Check out Math.exp


-- Adam Maass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top