Reputation: 179
I am using Javax.Units package in my project, to write some formual's. I am trying to write this line of code:
Unit newton = SI.NEWTON;
Unit newton09 = newton.pow(0.9);//not allowing me to input decimal value 0.9
The pow method only takes int as parameter, but I am looking for float or double as parameters.How can i write float or double in parameter?
Upvotes: 0
Views: 51
Reputation: 61540
I think you need to take a step back and recall what exponentiation means, especially with fractional exponents. You are trying to raise some value X
to some power M/N
.
If you recall what M/N
means from your arithmetic class, it is the same as M * 1/N
. This is important because it means you can phrase your expression like this:
X^M^(1/n)
So we have this equivalence :
X^(M/N) == X^M^(1/N)
and anything raised to the 1/N
is the same as taking the N
th root, so you can have an equivalent expression by computing this:
Nroot( X^M )
which in that API, would be:
Unit newton09 = newton.pow(9).root(10);
Upvotes: 1
Reputation: 8386
You could make use of the root()
and pow()
methods. A number, n
, taken to the 0.9 power is equivalent to n
taken to the 9/10 power, which in turn is equal to the 10th root of (n
taken to the 9th power). So, you could have this using only int
s:
Unit newton09 = newton.pow(9).root(10);
Upvotes: 1