When one vectorized their code the idea is to have the three or four components processed side by side.
Re-examine your loops as you have a problem. They're all exclusive but some are {0...2} and some are {0...3} for XYZ and XYZW processing. Was that intentional?
You haven't shown your declarations so difficult to tell if you're out of range thus causing your segmentation fault.
Also you only show snippets but do a pre-divide by zero check! Typically in vectors you're just not dividing a vector by a scalar. You are generating a product by multiplying a vector by a reciprocal scalar. If that is the case, if the divisor (typically a magnitude) is very close to zero, then don't do the 'division'. As the divident approaches zero, the result of the reciprocal-square root is negligible thus use the algebraic multiplicative identity (N = N * 1) thus N = N.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
Offline 891 posts
since Jun 2009