For some reason if I do 1.0 - Double.leastNonzeroMagnitude it returns 1.0.
First question, why?
Second, how can I get the smallest Double that is bigger than zero and actually works when I do some math?
Ps.: The reason I'm looking for this is to avoid some NaNs I'm getting when multiplying the sigmoid derivative with a cross entropy loss derivative.
A) sigmoid: 1 / (1 + exp(-z))
B) sigmoid derivative: sigmoid * (1 - sigmoid) // s * (1 - s)
C) cross entropy loss derivative: -y / s + (1 - y) / (1 - s)
B * C = s - y
Multiplying B and C should give me an actual number, but I'm calculating B, then calculating C, then multiplying the two, which is giving me NaN in some cases (because of division by zero on B).
Ps.2: I do know that having epsilon = 1e-16 and simply add that to my functions works, but I'm looking for something "more correct", if you know what I mean.
EDIT:
Explaining why this question is not a duplicate of the one mentioned, on this one I'm asking for the solution for an "epsilon" number, not why floating point math is broken. I don't care that much about the low level details, I just want a solution that is reliable in the future.