diff --git a/include/volume/volume_sequence_of_balls.hpp b/include/volume/volume_sequence_of_balls.hpp index cf9fd7350..fc1342cee 100644 --- a/include/volume/volume_sequence_of_balls.hpp +++ b/include/volume/volume_sequence_of_balls.hpp @@ -82,7 +82,7 @@ double volume_sequence_of_balls(Polytope const& Pin, c = Point(n); // Scale by number of threads and prevent edge case rnum=0 from producing overflow later - rnum = rnum >= n_threads ? rnum/n_threads : 1u; + rnum = rnum >= 2*n_threads ? rnum/n_threads : 2u; NT vol = NT(0); // Perform the procedure for a number of threads and then take the average diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0292fb15e..090cf5c79 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -243,6 +243,8 @@ else () add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) + add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) + set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) diff --git a/test/volume_sob_hpolytope.cpp b/test/volume_sob_hpolytope.cpp index 4fc9b37f9..18fa28bb0 100644 --- a/test/volume_sob_hpolytope.cpp +++ b/test/volume_sob_hpolytope.cpp @@ -268,6 +268,18 @@ void call_test_skinny_cube() { //test_volume(P, 104857600, 104857600.0); } +template +void call_test_cube_overflow() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "--- Testing volume of H-cube1" << std::endl; + P = generate_cube(1, false); + test_volume(P, 2, 2, 2, 2, 2); +} + TEST_CASE("cube") { call_test_cube(); @@ -293,3 +305,7 @@ TEST_CASE("simplex") { TEST_CASE("skinny_cube") { call_test_skinny_cube(); } + +TEST_CASE("cube_overflow") { + call_test_cube_overflow(); +}