4

I have two values: X = -78.0921 and Y = -64.6294. Now, when I want to compute Math.Pow(X, Y) it returns NaN. What should I do? How can I solve this problem?

How should I calculate this power? Is there any other function that can calculate this?...or maybe it is not defined mathematically ?

4

6 に答える 6

7

NaN入力が次のように一致するため、返されることを意味していると思います。

x < 0 ですが、NegativeInfinity ではありません。y が整数、NegativeInfinity、PositiveInfinity のいずれでもない

ドキュメントに従って、どちらが正しいですか。

于 2013-05-14T13:54:14.503 に答える
0

同様の問題があり、以下に示すように処理しました。必要に応じて最小値と最大値を調整する必要があります。私の場合は 0 と 10 です。

      double alpha =  FastMath.pow(weight, parameters.getAlpha());
      if(alpha == Double.NEGATIVE_INFINITY) {
          alpha = 0d;
      } 
      if(alpha == Double.POSITIVE_INFINITY) {
          alpha = 10d;
      } 

      double beta = FastMath.pow(1d / distanceMatrix[row][column],
           parameters.getBeta());
      if(beta == Double.NEGATIVE_INFINITY) {
          beta = 0d;
      } 
      if(beta == Double.POSITIVE_INFINITY) {
          beta = 10d;
      } 
于 2015-04-28T12:47:03.433 に答える