Re: [AD] div-by-zero... math3d.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


aj wrote:
normalize_vector_f()

in /allegro419/src/math3d.c

could the vector_length_f()  return zero ?

I replied:
> Certainly, e.g., if all three arguments are zero.

Maybe I should elaborate a bit on that: If all three arguments are zero, then the local variable `length' becomes infinity and *x=*y=*z=NaN. However, it seems possible that, the arguments are initially moderately tiny but not zero, so that their squares are zero. In this case `length' becomes infinity but *x=*y=*z=0.0, a little bit inconsistent with the previous case.

OTOH, I think there is probably a problem in the user code in such a case; you shouldn't try to normalize so small vectors anyway.

> Btw, I think this routine would better be implemented as
>
>    fixhypot(x, fixhypot(y,z))
>
> to avoid the current loss of precision.

Um, sorry, I now changed context, and was of course referring to the implementation of `vector_length()'.

Sven





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/