A reference to the JVM instruction set specifically prohibits bytecodes that do math with floating point, throwing exceptions and rigidly determines how they should work when the NaN operand. If there is a way to do this, it will either require you to explicitly throw exceptions from NaN, or to use a special compiler to insert these checks for you.
One option that may be useful is to write a function like this:
public static float check(float value) {
if (Float.isNaN(value))
throw new ArithmeticException("NaN");
return value;
}
With this, you can write code for this:
float f = check(myOtherFloat / yetAnotherFloat);
Then this will happen and throw an error. Ideally, with a short function name, this would not be too intrusive.
W
source
share