Home > Mobile >  How to convert extremely small exp values to 0?
How to convert extremely small exp values to 0?

Time:12-21

I'm doing Gram-Schmidt Orthogonalization process. At some point I'm getting output 3D vectors with values extremely small. Basically the values are zeros. How to deal with values such as -3.5527136788005009 * 10^-15? How to convert them to zero or compare if it is almost zero?

CodePudding user response:

You asked "How to convert them to zero?" If you want to convert extremely small values to zero you can use a simple if statement:

const double delta = 0.000000001;
if (x < delta && x > -delta) { x = 0; }

CodePudding user response:

I did research on my old code and I've found this little func:

static const double eps = 1e-10;

bool isZero(double value) const
{
    return std::abs(value) <= eps;
}
  •  Tags:  
  • c
  • Related