
Currently following situation does not generate a bad_numeric_cast. <test> unsigned int ui = std::numeric_limits< unsigned int >::max() ; int i = boost::numeric_cast< int >( ui ) ; </test> Nevertheless 'i' is -1 instead of some very big number. To catch this kind of error, I propose to apply following patch to boost/cast.hpp (in attachment). The current implementation casts the value for to the target-type and back to the original type and verifies that it is still the same value. For the example above, the intermediate result will be -1 although casting it back to the original type will result in the original value. So the patch verifies that this intermediate result will not be negative. If the patch is accepted I will also add a test in the current regression-test of numeric_cast. toon -- Check out our training program on acoustics and register on-line at http://www.fft.be/?id=35

"Toon Knapen" <toon.knapen@fft.be> escribió en el mensaje news:4264B460.1060205@fft.be...
Currently following situation does not generate a bad_numeric_cast.
<test> unsigned int ui = std::numeric_limits< unsigned int >::max() ; int i = boost::numeric_cast< int >( ui ) ; </test>
Nevertheless 'i' is -1 instead of some very big number. To catch this kind of error, I propose to apply following patch to boost/cast.hpp (in attachment).
Take a look at the current replacement of _that_ numeric_cast<>: http://www.boost.org/libs/numeric/conversion/doc/numeric_cast.html Best Fernando Cacciola SciSoft
participants (2)
-
Fernando Cacciola
-
Toon Knapen