I wish to round a floating point number to set precision and return the result from a function. For example, I currently have the following function:
inline bool R3Point::
operator==(const R3Point& point) const
{
// Return whether point is equal
return ((v[0] == point.v[0]) && (v[1] == point.v[1]) && (v[2] == point.v[2]));
}
What I wish to do is instead of doing a direct v[i] == point.v[i]
comparison, I wish to compare only digits to a certain set precision, so that if v[i] = 0.33349999999999996
and point.v[i] = 0.33350000000000002
, my equal comparison will result in TRUE.
I am aware that there's a c++ smanip setprecision ( int n );
function and I've seen it used a lot when displaying output on screen using cout
. However, I'm not sure if this can be used within the function like I described.
Thanks.