posted 11 years ago
Welcome to JavaRanch!
What have you tried so far? You might start small to make sure you're using the methods correctly  for example, just print out the square root of 9, or try raising 5 to the 2nd power.
What have you tried so far? You might start small to make sure you're using the methods correctly  for example, just print out the square root of 9, or try raising 5 to the 2nd power.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Katrina Cobb
Greenhorn
Posts: 5
posted 11 years ago
You do not need, and should not use, pow() for this expression. All the powers are integers, so you can just use ordinary multiplication, which is much faster than pow() and more accurate, too.
Also, you have a polynomial there, so you can refactor, to make the number of operations smaller.
For instance: 
x^4 + 2 x^3 + 3 x^2 + x + 4
is refactorable to
4 + x ( 1 + x ( 3 + x ( 2 + x ) ) )
Or something like that. The general point is that, when you have to implement a mathematical formula in a computer program, you should first take a good look at the formula itself, to see if it can be simplified and to see how it is best implemented on a computer.
[ September 25, 2006: Message edited by: Peter Chase ]
Also, you have a polynomial there, so you can refactor, to make the number of operations smaller.
For instance: 
x^4 + 2 x^3 + 3 x^2 + x + 4
is refactorable to
4 + x ( 1 + x ( 3 + x ( 2 + x ) ) )
Or something like that. The general point is that, when you have to implement a mathematical formula in a computer program, you should first take a good look at the formula itself, to see if it can be simplified and to see how it is best implemented on a computer.
[ September 25, 2006: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
