Skip to content

Commit

Permalink
Merge pull request #123 from bluescarni/pr/assert_fix
Browse files Browse the repository at this point in the history
Fix assert misfiring
  • Loading branch information
bluescarni authored Apr 8, 2021
2 parents a082fc0 + 987b010 commit e3549f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka VERSION 0.6.0 LANGUAGES CXX C)
project(heyoka VERSION 0.6.1 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -210,7 +210,7 @@ if(HEYOKA_BUILD_STATIC_LIBRARY)
else()
# Setup of the heyoka shared library.
add_library(heyoka SHARED "${HEYOKA_SRC_FILES}")
set_property(TARGET heyoka PROPERTY VERSION "6.0")
set_property(TARGET heyoka PROPERTY VERSION "6.1")
set_property(TARGET heyoka PROPERTY SOVERSION 6)
set_target_properties(heyoka PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(heyoka PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
Expand Down
9 changes: 9 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

0.6.1 (unreleased)
------------------

Fix
~~~

- Fix an assertion misfiring in the event detection function
(`#123 <https://github.com/bluescarni/heyoka/pull/123>`__).

0.6.0 (2021-04-06)
------------------

Expand Down
7 changes: 5 additions & 2 deletions src/detail/event_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ std::uint32_t count_sign_changes(InputIt a, std::uint32_t n)
{
assert(n > 0u);

using std::isnan;

std::uint32_t retval = 0;

// Start from index 0 and move forward
Expand All @@ -204,7 +206,9 @@ std::uint32_t count_sign_changes(InputIt a, std::uint32_t n)
// Determine if a sign change occurred wrt
// the last nonzero coefficient found.
const auto cur_sign = sgn(a[idx]);
assert(sgn(a[last_nz_idx]));
// NOTE: don't run the assertion check if
// we are dealing with nans.
assert(isnan(a[last_nz_idx]) || sgn(a[last_nz_idx]));
retval += (cur_sign + sgn(a[last_nz_idx])) == 0;

// Update last_nz_idx if necessary.
Expand All @@ -221,7 +225,6 @@ std::uint32_t count_sign_changes(InputIt a, std::uint32_t n)
bool has_nan = false;

for (std::uint32_t i = 0; i <= n; ++i) {
using std::isnan;
if (isnan(a[i])) {
has_nan = true;
}
Expand Down

0 comments on commit e3549f2

Please sign in to comment.