I know what Java Double.NaN is. I have some Java code that produces NaN.
Double.NaN
NaN
// calculate errors delta = m1 + m2 - M; eta = f1 + f2
Have you tried sprinkling your code with System.out.println statements to determine exactly where NaNs start occuring?
System.out.println