|
Boost Users : |
From: Peter Piehler (ppiehler_at_[hidden])
Date: 2004-06-14 07:28:29
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net