I am trying to output NaN in string format when x is NaN. However, the console throws up String cannot be converted to double error when I am trying to return string of "NaN" when Double.isNaN is true. I tried parsing string r as a double using Double.parseDouble() but to no avail.
Here is my code:
public static double heaviside(double x) {
String r = "NaN";
r = Double.parseDouble(r);
double result;
if (Double.isNaN(x)) return r;
else if (x < 0.0) return result = 0.0;
else if (x == 0.0) return result = 0.5;
else return result = 1.0;
}
Console output
ActivationFunction.java:6: error: incompatible types: double cannot be converted to String r = Double.parseDouble(r); ^ ActivationFunction.java:8: error: incompatible types: String cannot be converted to double if (Double.isNaN(x)) return r; ^
xis NaN, why don't you just returnx?