# Thread: Raising a real number

1. Member
Join Date
Jan 2014
Posts
4
Rep Power
0

## Raising a real number

Hey, guys

Am very new to this programming world, and i choose java, am having a little bit of problem...
am trying to raise a real number to a negative value e.g
x-y(x raised to power -y) which can also be written like 1/xk . am trying to run th program each time bt it doesnt give me the desired result. please help....

here is the code

public class RaiseRealPower {
public void run(){
}

private double raiseIntToPower(double val,double pow) {

if (pow>0) return Math.pow(val,pow);
if (pow<0) return (1)/(Math.pow(val,pow));
else return 1;

}
}

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,155
Rep Power
12

## Re: Raising a real number

What result are you getting and what result are you expecting?

Regards,
Jim

3. Senior Member
Join Date
Oct 2012
Posts
176
Rep Power
6

## Re: Raising a real number

When it does 1/x^y wont why still be positive and thus end up with one divided by x raised to the negative y

4. Member
Join Date
Jan 2014
Posts
4
Rep Power
0

## Re: Raising a real number

@jim829, for instance 2^2 gives me 4, and 2^-2 gives me 1..... i was expecting 2^-2=0.25....

5. Member
Join Date
Jan 2014
Posts
4
Rep Power
0

## Re: Raising a real number

Originally Posted by Daryn
When it does 1/x^y wont why still be positive and thus end up with one divided by x raised to the negative y
yeah! i've gotten the idea! let me try it out!

6. Member
Join Date
Jan 2014
Posts
4
Rep Power
0

## Re: Raising a real number

Thanks Daryn... it worked

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•