mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-11 12:02:30 +00:00
Implemented divide operations
updated test_add
This commit is contained in:
@@ -27,74 +27,86 @@ bool test_divide(
|
||||
<< "testing "
|
||||
<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
{
|
||||
boost::numeric::safe<T1> t1 = v1;
|
||||
// presuming native policy
|
||||
boost::numeric::safe<decltype(v1 / v2)> result;
|
||||
|
||||
boost::numeric::safe<T1> t1 = v1;
|
||||
BOOST_TYPEOF_TPL(T1() / T2()) result;
|
||||
|
||||
try{
|
||||
result = t1 / v2;
|
||||
|
||||
if(expected_result != '.'){
|
||||
//if(expected_result == 'x'){
|
||||
std::cout
|
||||
<< "failed to detect error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " ! = "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
result = t1 / v2;
|
||||
try{
|
||||
result = t1 / v2;
|
||||
static_assert(
|
||||
boost::numeric::is_safe<decltype(t1 + v2)>::value,
|
||||
"Expression failed to return safe type"
|
||||
);
|
||||
if(expected_result == 'x'){
|
||||
std::cout
|
||||
<< "failed to detect error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " ! = "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
t1 / v2;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(std::exception & e){
|
||||
if(expected_result == '.'){
|
||||
std::cout
|
||||
<< "erroneously detected error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " == "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
t1 / v2;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(std::range_error){
|
||||
if(expected_result != 'x'){
|
||||
//if(expected_result == '.'){
|
||||
std::cout
|
||||
<< "erroneously detected error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " == "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
result = t1 / v2;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
boost::numeric::safe<T2> t2 = v2;
|
||||
{
|
||||
boost::numeric::safe<T1> t1 = v1;
|
||||
boost::numeric::safe<T2> t2 = v2;
|
||||
|
||||
try{
|
||||
result = t1 / t2;
|
||||
// presuming native policy
|
||||
boost::numeric::safe<decltype(v1 + v2)> result;
|
||||
|
||||
if(expected_result != '.'){
|
||||
//if(expected_result == 'x'){
|
||||
std::cout
|
||||
<< "failed to detect error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " ! = "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
result = t1 / t2;
|
||||
try{
|
||||
result = t1 / t2;
|
||||
|
||||
static_assert(
|
||||
boost::numeric::is_safe<decltype(t1 + t2)>::value,
|
||||
"Expression failed to return safe type"
|
||||
);
|
||||
|
||||
if(expected_result == 'x'){
|
||||
std::cout
|
||||
<< "failed to detect error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " ! = "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
t1 / t2;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(std::range_error){
|
||||
if(expected_result != 'x'){
|
||||
//if(expected_result == '.'){
|
||||
std::cout
|
||||
<< "erroneously detected error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " == "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
result = t1 / t2;
|
||||
catch(std::exception & e){
|
||||
if(expected_result == '.'){
|
||||
std::cout
|
||||
<< "erroneously detected error in division "
|
||||
<< std::hex << result << "(" << std::dec << result << ")"
|
||||
<< " == "<< av1 << " / " << av2
|
||||
<< std::endl;
|
||||
try{
|
||||
t1 / t2;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
catch(...){}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -113,38 +125,38 @@ const char *test_division_result[VALUE_ARRAY_SIZE] = {
|
||||
// 01234567890123456789012345678901
|
||||
/* 0*/ "................................",
|
||||
/* 1*/ "................................",
|
||||
/* 2*/ "...x...x...x...x................",
|
||||
/* 3*/ "................................",
|
||||
/* 2*/ "........................xxxxxxxx",
|
||||
/* 3*/ "........................xxxxxxxx",
|
||||
/* 4*/ ".................................",
|
||||
/* 5*/ "................................",
|
||||
/* 6*/ "...x...x...x...x................",
|
||||
/* 7*/ "................................",
|
||||
/* 6*/ "........................xxxxxxxx",
|
||||
/* 7*/ "........................xxxxxxxx",
|
||||
|
||||
/* 8*/ "................................",
|
||||
/* 9*/ "................................",
|
||||
/*10*/ "...x...x...x...x................",
|
||||
/*11*/ "................................",
|
||||
/*10*/ "..xx..xx..xx............xxxxxxxx",
|
||||
/*11*/ "........................xxxxxxxx",
|
||||
/*12*/ "................................",
|
||||
/*13*/ "................................",
|
||||
/*14*/ "...x...x...x...x................",
|
||||
/*15*/ "................................",
|
||||
/*14*/ "..xx..xx..xx..xx............xxxx",
|
||||
/*15*/ "............................xxxx",
|
||||
|
||||
// 0 0 0 0
|
||||
// 01234567012345670123456701234567
|
||||
// 01234567890123456789012345678901
|
||||
/*16*/ "..xx..xx..xx..xx................",
|
||||
/*17*/ "..xx..xx..xx..xx................",
|
||||
/*18*/ "..xx..xx..xx..xx................",
|
||||
/*19*/ "..xx..xx..xx..xx................",
|
||||
/*20*/ "..xx..xx..xx..xx................",
|
||||
/*21*/ "..xx..xx..xx..xx................",
|
||||
/*22*/ "..xx..xx..xx..xx................",
|
||||
/*23*/ "..xx..xx..xx..xx................",
|
||||
/*16*/ "................................",
|
||||
/*17*/ "................................",
|
||||
/*18*/ "................................",
|
||||
/*19*/ "................................",
|
||||
/*20*/ "................................",
|
||||
/*21*/ "................................",
|
||||
/*22*/ "................................",
|
||||
/*23*/ "................................",
|
||||
|
||||
/*24*/ "..xx..xx..xx..xx................",
|
||||
/*25*/ "..xx..xx..xx..xx................",
|
||||
/*26*/ "..xx..xx..xx..xx................",
|
||||
/*27*/ "..xx..xx..xx..xx................",
|
||||
/*24*/ "..xx..xx..xx....................",
|
||||
/*25*/ "..xx..xx..xx....................",
|
||||
/*26*/ "..xx..xx..xx....................",
|
||||
/*27*/ "..xx..xx..xx....................",
|
||||
/*28*/ "..xx..xx..xx..xx................",
|
||||
/*29*/ "..xx..xx..xx..xx................",
|
||||
/*30*/ "..xx..xx..xx..xx................",
|
||||
|
||||
Reference in New Issue
Block a user