Finding the maximum of a floating point counter

×

Error message

  • Notice: Undefined index: value in answers_field_get_value() (line 24 of H:\root\home\marcluo777-001\www\healthcentre\sites\all\modules\answers\includes\answers.field_utils.inc).
  • Notice: Undefined index: value in answers_field_get_value() (line 24 of H:\root\home\marcluo777-001\www\healthcentre\sites\all\modules\answers\includes\answers.field_utils.inc).

Primary tabs

+1
+1
-1

My apologies if this has been asked before, but I cannot find it.

I was wondering if there is a way to calculate the point at which a single precision floating point number that is used as a counter will reach a 'maximum' (the point at which it is no longer able to add another value due to loss of precision).

For example, if I continuously add 0.1f to a float I will eventually reach a point where the value does not change

Answer 7

+1
+1
-1

Yes it is possible. there is std::numeric_limits::epsilon() which defines smallest value which can increase value 1.0.

Using this you can calculate this limit for any number.

In C there is DBL_EPSILON

So in your case this goes like this: