4 Replies - 253 Views - Last Post: 03 October 2012 - 07:40 PM Rate Topic: -----

#1 thorax232  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 10-September 12

pow (double, double)

Posted 23 September 2012 - 02:10 PM

I'm having a ton of trouble with this. I have the code:

double discrim = Math.pow((b*B)/> - (4*a*c));


And am getting the following error:

Prog10.java:15: pow(double,double) in java.lang.Math cannot be applied to (double)
                double discrim = Math.pow((b*B)/> - (4*a*c));
                                     ^
1 error


I've read a couple of forums relating to this error but I don't understand the answers, talking about how pow need two arguments? I just want to assign the variable "dicrim" to the formula. Is there something unique I have to do for exponents? I figured b*b would be a good substitute for b^2. =/

Thanks for your time and patience. :)

I should mention in the code it is both lowercase b's. I think the forum auto corrected that somehow.

Is This A Good Question/Topic? 0
  • +

Replies To: pow (double, double)

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4334
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: pow (double, double)

Posted 23 September 2012 - 02:11 PM

Pow takes two values. The base value (the value raised to some value) and the exponential value (the power). For instance to raise 10 to the power of 2 you would do Math.pow(10.0,2.0). In your code above you have one value only. (b*B ) - (4*a*c) is boiled down to a single number. Is (b*B ) - (4*a*c) the base or the power? You need to add a comma and then a second number. Both numbers should be a double.

:)

This post has been edited by Martyr2: 23 September 2012 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 thorax232  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 10-September 12

Re: pow (double, double)

Posted 24 September 2012 - 07:16 AM

View PostMartyr2, on 23 September 2012 - 02:11 PM, said:

Pow takes two values. The base value (the value raised to some value) and the exponential value (the power). For instance to raise 10 to the power of 2 you would do Math.pow(10.0,2.0). In your code above you have one value only. (b*B ) - (4*a*c) is boiled down to a single number. Is (b*B ) - (4*a*c) the base or the power? You need to add a comma and then a second number. Both numbers should be a double.

:)


Hm, well I'm trying to square a variable given by a user. I ask them to enter a, b and c. Could I use 1? Like:
(b,b*1)-(4*a*c) or (b*b*1)-(4*a*c)

>.< I'll give a try when I'm home later but I have a feeling that won't work either. Maybe you could show what your thinking of?

Also I've tried (b,2)-(4*a*c) but I got the same error with it. =/ Maybe I should add 1 to that version... lol I don't know. :(

Woops, I meant b,2*1 on the first snippet.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: pow (double, double)

Posted 24 September 2012 - 07:28 AM

If power of two easier to write val*val rather than Math.pow(val, 2.0)
but pow(val, 2.0) is valid
to your discriminent is

double bSquare = b * b:
double fourAC = 4.0 * a * c;

double r1 = bSquare + fourAC;
double r2 = bSquare - fourAC;
Was This Post Helpful? 1
  • +
  • -

#5 thorax232  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 10-September 12

Re: pow (double, double)

Posted 03 October 2012 - 07:40 PM

Sorry I forgot to post back on this. I was being kind of dumb. What I needed was.

(b,2.0) I was forgetting the .0 lol, thanks for the responses though. :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1