Re: [AD] div-by-zero... math3d.c |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Monday 17 March 2003 4:30 pm, Sven Sandberg wrote:
> I think you are right about the zero vector, we may well leave the
> result undefined. But I also think the current implementation may give
> strange results for vectors close to but different from zero, because if
> their squares are zero then vector_length() returns zero. What about
> the following algorithm:
[snip]
I honestly think the best solution would be to do the arithmetic using
double-precision values. A float can go down to 1e-38 before it becomes
subnormal (and slow) and starts losing precision. A double can go down to
1e-some_three_digit_number. So the smallest float, cast to double, and
squared, would be will within the range of a double. As for efficiency, the
FPU on an x86 processor probably does everything using 10-bit (the
nonstandard 'long double') precision anyway, so we're not losing anything.
Ben