Page 1 of 1

Division by zero on Alpha hardware

Posted: 10.09.2003, 22:58
by zoop
Hi!

I have a bug report here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=146305
and I think the bug is still present in 1.3.0.

The problem lies in celmath/vecmath.h:
template<class T> void Vector3<T>::normalize()
{
T s = 1 / (T) sqrt(x * x + y * y + z * z);
x *= s;
y *= s;
z *= s;
}

The division by zero obviously arises for x=y=z=0.

Alpha Hardware is not IEEE compatible thus dividing by zero does not yield "inf" but results in a Floating Point Exception which kills celestia.

I don't know what you expect to happen when you call normalize on a zero vector but it should probably be checked against beforehand.

The other alternative (if you really expect <0,0,0> to be "normalized" to <inf,inf,inf>) is to include the -mieee flag for gcc at least on the Alpha architecture. But that would mean a performance penalty for Alpha users.

Mika