Math.pow Question

  • Thread starter Michael B. Williams
  • Start date
M

Michael B. Williams

Please help

The Math.pow call is retuning Infinity? What am I doing wrong - be
gental I java newbie. Thanks in advance

import java.math.*;


double
interest = .0575,
J = 0,
N = 0,
ftemp;

J = interest / 1200 ;
ftemp = ( 1-(1+J) );
N = N * (-1);

System.out.println( Math.pow( ftemp , N ) );
 
W

Woebegone

Michael B. Williams said:
Please help

The Math.pow call is retuning Infinity? What am I doing wrong - be
gental I java newbie. Thanks in advance

import java.math.*;


double
interest = .0575,
J = 0,
N = 0,
ftemp;

J = interest / 1200 ;
ftemp = ( 1-(1+J) );
N = N * (-1);

System.out.println( Math.pow( ftemp , N ) );

My result is 1.0, which seems reasonable to me since your exponent is -0.0:
is this the exact code that produces Infinity? By my reckoning, x^(-y) ==
1/(x^y), so you have ftemp^(-0) == 1/(ftemp^0) == 1/1 == 1. The expected
results are laid out fairly clearly in the JavaDoc:

"Returns the value of the first argument raised to the power of the second
argument. Special cases:
- If the second argument is positive or negative zero, then the result is
1.0. "

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html#pow(double,
double)
 
C

Chris Smith

Michael said:
The Math.pow call is retuning Infinity? What am I doing wrong - be
gental I java newbie. Thanks in advance

When I compile and run your code, I get 1.0 as the answer, not Infinity.
That's the result I'd expect. If you're still getting 1.0, then I
suspect that's not the code that you're compiling or running. Are you
sure you aren't running an older version of the code by mistake?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top