Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Matt J <mjo...@gm...> - 2009-03-05 23:22:02
|
I do not think that is the point Christer is making. On P. 438 of his book he has an example of code that removes an explicit check for divide by zero (by assuming the behavior of IEEE and the behavior of NaN, which could be a trap representation), and he suggests is not portable but can be used as a 'quick and dirty' solution, because you can check for an error using exception handling and fall back to a more robust version. So why can't that exact same argument be made with a union cast? Also, if that is legal code, why isn't a union cast? To me it seems like when you are trying to optimize something for fun and by definition it is machine specific because your interpreting an IEEE float as a series of bits, beating someone over the head with a standards book is a little bit of a cheap shot - especially when it is legal by the latest C99 TC3 standards and works on a wide range of compilers including, but not limited to, GCC w/ strict aliasing > The point more is that just because it works some of the time as an > artefact of a "correct" implementation (on most platforms, ints and floats > being the same size etc), it doesn't mean that it will work everytime (and > it isn't portable). One of the more important points is that (for example) > in C++98 compilers, there is no guarantee on the number of bits for most of > the integral data types other than a minimal possible size and representable > range. > > http://en.wikibooks.org/wiki/C%2B%2B_Programming/Data_Types_Reference > > Cheers, > Conor > |