C++ Adding 1 to very small number?
问题 I'm just trying to compute a good sigmoid function in C++ (and efficient). So i have to do something like: 1/(1 + exp(-x)) The problem is, when X becomes big (or even small), the result of 1 + e turns to be 0 or 1 For example, 1 + exp(-30) = 1 But this is incorrect... How can we add very small (or big) numbers easily and efficiently ? Datatype I am using : double Here is the code snippet : double Quaternion::sigmoidReal(double v){ return 1.0 / ( 1.0 + exp(-v) ) ; } Thanks ! 回答1: I think you