
On Mon, Jan 26, 2009 at 4:13 PM, Matthieu Brucher
So, I am still confident that converting integers greater that 2^24 to float using boost::numeric_cast must raise an exception. Has this behavior changed in the newer versions of Boost?
To be more accurate, this would mean testing the value in the numerical cast, as there are no ASM instruction to do this on the usual platforms. The cost that this would induce is probably too high a price to pay. I think the best course of action would be to write your own cast for this specific use.
I agree with you that testing the value in numeric_cast is a bad thing. But I think that numeric_cast is not delivering what it advertises. For me a well formed cast is always one where A can be converted to B and back to A without any lose in the representation. Unfortunately, with the current implementation A (an integer) can be converted to B (a float) but the resulting value can not be casted back to an integer representing A. Maybe It is a good idea to provide an additional implementation of a function similar to numeric_cast (say strict_numeric_cast) behaving like that. Best. -- Hermann Rodrigues hermann@csr.ufmg.br Centro de Sensoriamento Remoto / UFMG http://www.csr.ufmg.br/dinamica