(Re:) (re;) Math.pow Question

  • Thread starter Michael B. Williams
  • Start date
M

Michael B. Williams

Sudsy said:
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.

I think that you need to pull out your old calculator -.0174 of
course I rounded it up besides it's not my algorithm anyway I'm just
trying to understand why Math.pow is behaving in an abnormal way. This
is the code


import java.math.*;

public class post
{

public static void main(String[] args)
{
int
term = 30,
amount = 200000,
principal = amount;


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


J = interest / (1200);

N = 30*12;


ftemp = ( 1-(1+J) );
N = N * (-1);


System.out.println( ftemp );

// ftemp = -4.791666666670302E-5


System.out.println( N );

// N = -360.0



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


// the output is Infinity I tried hardcoding it to -360

}
}
 
B

Boudewijn Dijkstra

Michael B. Williams said:
Sudsy said:
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.

I think that you need to pull out your old calculator -.0174 of
course I rounded it up besides it's not my algorithm anyway I'm just
trying to understand why Math.pow is behaving in an abnormal way. This
is the code

[snip]
// ftemp = -4.791666666670302E-5
// N = -360.0
System.out.println( Math.pow( ftemp , N ) );

// the output is Infinity I tried hardcoding it to -360

The Windows calculator gives 1,0588257359160254305806492692446e+1555.
I think few people's "old calculator" can calculate this.
Even the largest positive finite double literal is 1.79769313486231570e+308,
so it is rounded up to +Infinity. This is not abnormal.
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top