wood burning stoves*
The moose likes Beginning Java and the fly likes Powers and the math. class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Powers and the math. class" Watch "Powers and the math. class" New topic
Author

Powers and the math. class

Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
I need to perform the following formula 1-(1+i)(power)-n
I know that i need to use the Math. class but im not sure on which one, i have tired maths.Floor and it didnt work (got a negative number) any help would be great as always .
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
I'd say you're looking for the static method Math.pow(). It works with positive or negative numbers.
...Assuming 'i' in your formula above isn't a reference to complex numbers, that is
--Tim
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I need to perform the following formula 1-(1+i)(power)-n
This doesn't look like a mathematical expression that I can parse, but I think you have a compounded interest in mind:
1 - (1 + i)^(-n)
If so, the corresponding Java code would be:

For more information, see the javadocs for the pow() method of the Math class
Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
Yup im thinking compound interest, sorry shoulda said that, ah so its .pow i thought i couldnt use that because i was using ints not doubles lol, well looks like im still n00b rock on d0de!
 
Consider Paul's rocket mass heater.
 
subject: Powers and the math. class