Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

machine precision

I wonder if there is something like eps to represent the value of machine precision in C++? Can I use it as the smallest positive number that a double can represent? Is it possible to use 1.0/eps as the max positive number that a double can represent? Where can I find eps in both C++ and C standard libraries?

Thanks and regards!


UPDATE:

For my purpose, I would like to compute a weight as reciprocal of a distance for something like inverse distance weighting interpolation (http://en.wikipedia.org/wiki/Inverse_distance_weighting).

double wgt = 0, wgt_tmp, result = 0;
for (int i = 0; i < num; i++)
{
   wgt_tmp = 1.0/dist[i];
   wgt += wgt_tmp;
   result += wgt_tmp * values[i];
}
results /= wgt;

However the distance can be 0 and I need to make the weight suitable for computation. If there is only one distance dist[i] is 0, I would like its corresponding value values[i] to be dominant. If there are several distances are 0, I would like to have their values to contribute equally to the result. Any idea how to implement it?

like image 274
Tim Avatar asked Aug 31 '26 16:08

Tim


1 Answers

Using #include <limits> you have

Small positive value = std::numeric_limits<float>::denorm_min()

Largest positive value = std::numeric_limits<float>::max()

Obviously this applies to other types as well.

See numeric_limits

And no, the inverse of the smallest positive value does not equal the largest.

like image 56
Peter Alexander Avatar answered Sep 02 '26 06:09

Peter Alexander