Skip to content

Fix interval - #18

Open
bourdin wants to merge 1 commit into
symengine:masterfrom
bourdin:fix-interval
Open

bourdin wants to merge 1 commit into
symengine:masterfrom
bourdin:fix-interval

Conversation

@bourdin

@bourdin bourdin commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes three bugs in interval (basic_interval in src/sets.f90):

  • All intervals were open. left_open and right_open were passed by
    reference to basic_set_interval, which takes ints by value, so SymEngine
    received an address. The interface now declares them with value.
  • Crash when an optional argument is absent. The function used
    present(left_open) .and. .not. left_open. Fortran does not short-circuit
    .and., so absent arguments were referenced. With fpm's default debug flags,
    test_basic segfaults there. With CMake it happened to work.
  • A closed end stayed closed in later calls. integer(c_int) :: a_left = 1, a_right = 1 implies save, so once a call set an end to closed, later calls
    kept it closed. The variables are now initialized at each call.

The default, when the optional arguments are omitted, is unchanged: both ends
are open.

Testing

test_basic now checks the intervals it creates, e.g. that
interval(1, 2, left_open=.true., right_open=.false.) is (1, 2]. Without the
fix, the new assertions fail with CMake, and test_basic crashes with fpm.
With the fix, test_basic passes in both (gfortran 16, macOS).

🤖 Generated with Claude Code

- left_open and right_open were passed by reference to basic_set_interval,
  which takes them by value, so all intervals were open.
- Absent optional arguments were referenced, because .and. does not short
  circuit. This crashed test_basic when built with fpm.
- The initialization of a_left and a_right implied save, so a closed end
  remained closed in subsequent calls.
@bourdin bourdin mentioned this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant