(re;) Math.pow Question

  • Thread starter Michael B. Williams
  • Start date
M

Michael B. Williams

Ooooopppps and sorry about the sniplet thanks again

/* and if this helps I using JCreator and j2sdk1.4.2_04 */

double
interest = .0575,
J = 0,

N = 360, /* I had zero */

ftemp;

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

// N would be -360
System.out.println( Math.pow( ftemp , N ) );



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


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
 
S

Sudsy

Michael said:
Ooooopppps and sorry about the sniplet thanks again

/* and if this helps I using JCreator and j2sdk1.4.2_04 */

double
interest = .0575,
J = 0,

N = 360, /* I had zero */

Why are you surprised at the infinity result? Using a value of 70 for N
provides a result of 2.3224057336909954E302, a HUGE number.
Methinks your algorithm is incorrect as you appear to want to calculate
daily interest (based on some of the math and the variable names).
I strongly suggest hitting the text books again or searching the 'net
for the correct algorithm.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top