Boost logo

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
-the maximum could not be handled correctly, for
int>::max()); doesn't throw a exception
-no precession handling, example:

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:
So I have extended the boost::numeric_cast for my
special requirements. You can download it under the
following link: .
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
numeric_cast_testcases.cpp(91): error in
"standard_cast_test": exception bad_numeric_cast is
numeric_cast_testcases.cpp(93): error in
"standard_cast_test": exception bad_numeric_cast is
numeric_cast_testcases.cpp(135): error in
"standard_cast_test": exception bad_numeric_cast is

*** 4 failures detected in test suite "numeric_cast

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

sorry for my bad english and code, it's the first time
that i ever have published.



Bestellen Sie Y! DSL und erhalten Sie die AVM "FritzBox SL" für 0€.
Sie sparen 119€ und bekommen 2 Monate Grundgebührbefreiung.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at