failures and featurerequest in/for numeric_cast
failures and featurerequest in/for numeric_cast I use boost in a little project for my study. In some cases the software must convert numeric datatypes. So I tried to convert with boost-library numeric_cast and found the following problems (gcc version 3.2.3 20030422): -the maximum could not be handled correctly, for example: +numeric_cast<int>(numeric_limits<unsigned int>::max()); doesn't throw a exception -no precession handling, example: +numeric_cast<float>(numric_limits<double>::epsilon()+1); doesn't throw a exception -no NaN, bounded/unbounded and exact handling. -no specialization. I need numeric_cast specializiation for: +numeric_limits-interface can't use for datatypes with caracteristics only known at runtime. +datatyps without static_cast support (example: gmp-library) So I have extended the boost::numeric_cast for my special requirements. You can download it under the following link: http://www.pienet.de/source/numeric_cast.tar.gz . Compile and run numeric_cast_tescases.cpp with USE_BOOST_CAST to test ::boost::numeric_cast. The output is: Running 2 test cases... numeric_cast_testcases.cpp(72): error in "standard_cast_test": exception bad_numeric_cast is expected numeric_cast_testcases.cpp(91): error in "standard_cast_test": exception bad_numeric_cast is expected numeric_cast_testcases.cpp(93): error in "standard_cast_test": exception bad_numeric_cast is expected numeric_cast_testcases.cpp(135): error in "standard_cast_test": exception bad_numeric_cast is expected *** 4 failures detected in test suite "numeric_cast Test" I think the line static_cast<X>(static_cast<Y>(x)) != x; is a tricky code. For X/Y==char/unsigned char,short/unsigned short etc. is always false. The compiler convert it only if the datatypes have not the same size/bytes or are between integers and floating points. sorry for my bad english and code, it's the first time that i ever have published. Peter Bestellen Sie Y! DSL und erhalten Sie die AVM "FritzBox SL" für 0. Sie sparen 119 und bekommen 2 Monate Grundgebührbefreiung. http://de.adsl.yahoo.com
Hi Peter, There is already a new version of numeric_cast<> which handles some of the issues you mentioned. It's in CVS now, and it will appear in the next release (circa the end of July _probably_) "boost/cast.hpp" hasn't changed yet, it will as soon as I see the code stablilized among different compilers. In the meantime, you can use "boost/numeric/conversion/cast.hpp" which contains the new version of numeric_cast<> I'll look at your code to see what can be incorporated in the new version. Thanks, Fernando Cacciola SciSoft
participants (2)
-
Fernando Cacciola
-
Peter Piehler