1

I normalized a vector and length of it should be 1. But the result of length method is 0.99999982

I don't know it's right or wrong. But if I print it out, the result is 1. Not 0.99999982( printed by cout )

But how std::cout knows it's 1? [This is my first question]

And another question is why the result of comparing function is false.

I have a comparing method like below. And lhs is the length of a vector and the rhs is just 1.

return (fabsf(rhs-lhs) <= FLT_EPSILON) ? true : false;

Result of this method is false.

Is length of the normalized vector is already wrong to be considered normalized? or epsilon is too small?

What did I wrong?

flight
  • 7,031
  • 4
  • 23
  • 30
SeniorLee
  • 785
  • 1
  • 11
  • 25

2 Answers2

4

The epsilon is too small. That's because epsilon is the smallest as it can be. (by definition)

So you will need a larger tolerance.

Mysticial
  • 452,826
  • 45
  • 327
  • 325
  • 3
    Right. `FLT_EPSILON` is absolutely not useful for a fuzzy equality test. The confusion comes because the symbol epsilon is often used in such formulas, but it's a different epsilon. – Ben Voigt Sep 21 '11 at 03:35
1

The IEEE standard requires that the result of addition, subtraction, multiplication and division be exactly rounded. The result must then be rounded to the nearest floating-point number. Floating point error is accumulated in the many operators it takes to normalize a vector. Like the other poster said FLT_EPSILON is too small.

David
  • 26,736
  • 18
  • 85
  • 135