Another question is about collinear points. This twist, I use integer arithmetic, and I'm looking for exact collinearity, not a fuzzy epsilon test.
With the built-in assembly, I can get the exact answer: the x86 multiplication instruction gives access to both the upper and the lower parts of the product, both of which are important when calculating the cross-product ( X - A ) x ( B - A ); I can just OR two halves together and check for zero. But I hope there is a way to do this in C, here is this:
- Overflow proof
- Portable
- Elegant
roughly in that order. And at the same time, the way to do this is that there is / NOT:
- enable casting in
double - use a larger integer type - suppose I already use the largest integer type available for my type of coordinate component
- false positives or false negatives are output.
I am not interested in the question of whether X is outside segment AB ; these are just four uninteresting comparisons.
My nightmare scenario is that I will have to split each coordinate component into two halves and do a long multiplication explicitly, so that I can track all the high halves in partial products. (And then you need to do the add-with-carry explicitly.)
c
Bernd jendrissek
source share