There is a method for raising a number to a power.
public static double raisedToPower(double a, double b) { return Math.pow(a, b); } As a result of the calculation, the method can return NaN and Infinity values, which in turn can break the program at the call point.
In my understanding, I have to process it inside a method (If NaN or Infinity, then return a key that can be processed outside the method). That is the question, what can be returned as a key or is there another way to handle this situation?
public static double raisedToPower(double a, double b) { double res = Math.pow(a, b); if (Double.isNaN(res) || Double.isInfinite(res)) { return key; } return res; }