Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## Correction in math methods

2013-03-17
2013-06-03
• You shouldn't compare floats like in this method : if (mag) . Much better and crash resistant would be if ( mag > 0.0001 ) for example. I guess theres more places in Assimp that thereis such a comparason ;)

```template<typename TReal>
inline aiQuaterniont<TReal>& aiQuaterniont<TReal>::Normalize()
{
// compute the magnitude and divide through it
const TReal mag = sqrt(x*x + y*y + z*z + w*w);
if (mag) // <- HERE :)
{
const TReal invMag = static_cast<TReal>(1.0)/mag;
x *= invMag;
y *= invMag;
z *= invMag;
w *= invMag;
}
return *this;
}
```

• Nope, this one is fine. The inversion works as long as mag is not zero, and the check ensures this. If you'd use a non-zero epsilon in this comparision instead, you'd be making assumptions about the range of the values, which is never a good idea.

• Well, technically a division could still be indeterminate for example if the numerator is super large and the denominator is super small. Luckily this can't happen for a normalize operation since the length is at least as huge as each of the components.

I therefore also think this is safe.

• Kim Kulling
2013-03-18

It's a common operation in numerical code to check, if the value is less than the machine epsilon value of the floating type. Special in bigger equations with a lot of multiplications / divisions such values can have evil effects.

But we do not work with stuff like this, so for me this is also ok.

Kimmi