I don't think this would work, as infinitely many points on "the sphere" will have the same key. So in the end the "find" will be indeterminate.
Printable View
Well, you could always make vector length the "primary" key and resolve equality using theta (polar coordinates).
The bottom line to all of this is by whatever means necessary, by hook or by crook, get out of using floating point values for lookups, counters, etc. and use something consistent that will work (if given the same data) all the time, on every compiler, no matter what compiler options are selected. I had a link to a PDF document, where a complex problem was described that was initially coded using floating point values, and it went through the steps of how they eventually solved the problem using integral values. The solution was not obvious, but it was possible. Wish I had it with me, but unfortunately, I don't have the URL right now.
I'm sure that many code reviewers would reject outright any usage of doubles as keys, unless that double can be normalized (and consistently normalized) to a proper integral key or value. How the normalization is done is what we're being paid for (if we are being paid to do it) -- it's our job to figure these things out. It may be easy or difficult, but it has to be done and honestly, should have been part of the design phase from the start.
I mention the debugging, because I can't imagine myself sitting there with an app that uses floating point this way, and then get a phone call or an email from customer support saying that they have someone who is getting strange and/or inconsistent results. Then what? It's either going to be some sort of patch fix (once you find out what the exact data the person is using, and that may take a while figuring that out), or you have to scrap the whole idea and go back to rethinking how to accomplish what you're trying to do.
Regards,
Paul McKenzie
The Bresenham line algorithm is a good example of replacing floating point calculations with integers.
http://en.wikipedia.org/wiki/Bresenh...line_algorithm