Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openvdb/openvdb/points/IndexFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class RandomLeafFilter
currentPoints += iter->pointCount();
}

const float factor = targetPoints > currentPoints ? 1.0f : float(targetPoints) / float(currentPoints);
const float denom = currentPoints > 0 ? float(currentPoints) : 1.0f; // Do not divide by zero.
const float factor = targetPoints > currentPoints ? 1.0f : float(targetPoints) / denom;

std::mt19937 generator(seed);
std::uniform_int_distribution<unsigned int> dist(0, std::numeric_limits<unsigned int>::max() - 1);
Expand Down
6 changes: 6 additions & 0 deletions openvdb/openvdb/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(OPENVDB_TESTS "" CACHE STRING [=[
\"Activate;NodeManager\" would build just the TestActivate.cc and TestNodeManager.cc
unit tests.]=])

option(OPENVDB_TESTS_FPE "Enable FP exceptions in unit tests (linux only)" OFF)

##########################################################################

message(STATUS "----------------------------------------------------")
Expand Down Expand Up @@ -196,6 +198,10 @@ else()
)
endif()

if (OPENVDB_TESTS_FPE)
add_compile_definitions(OPENVDB_TESTS_FPE)
endif()

add_executable(vdb_test ${UNITTEST_SOURCE_FILES})

# Blosc and ZLib are hidden dependencies for the core library
Expand Down
12 changes: 12 additions & 0 deletions openvdb/openvdb/unittest/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@
#include <string>
#include <vector>

#if defined(__linux__) && defined(OPENVDB_TESTS_FPE)
#include <fenv.h>
#endif

#include <gtest/gtest.h>

int
main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);

#if defined(__linux__) && defined(OPENVDB_TESTS_FPE)
int excepts = FE_DIVBYZERO;
// Note: NO FE_OVERFLOW as some unit tests don't pass with that.
// Note: NO FE_INVALID as some unit tests don't pass with that.
feenableexcept(excepts);
#endif

return RUN_ALL_TESTS();
}
Loading