2 ms·
I recently implemented dijkstra's shortest path using nearest neighbor nodes on a 3D image problem. While IEEE-745 is usually just a pain for me, in this case i
by tehjoker 8y ago
I recently implemented dijkstra's shortest path using nearest neighbor nodes on a 3D image problem. While IEEE-745 is usually just a pain for me, in this case it was pretty cool. Instead of allocating a separate boolean array of "visited" nodes, I just used negative numbers to denote visited. Since negative zero is a thing, I didn't have to add any exceptions to handle zero distance.
- phkahler 8y agoThat's a nice hack, but you're violating what many people consider a tenet of writing good code. I don't consider that an argument in favor of negative zero and all the baggage of IEEE 754.
- tehjoker 8y agoFwiw, in my code, I got to write "-0" explicitly and the method for checking is std::signbit(x)