Skip to content

Conversation

@Ariyn
Copy link
Owner

@Ariyn Ariyn commented Jun 3, 2025

The FlipFlop gate was previously implemented with D flip-flop behavior. This commit corrects the Handler function in gate/flipflop.go to implement the proper SR latch logic:

  • S=1, R=0 sets Q=1, Q'=0
  • S=0, R=1 sets Q=0, Q'=1
  • S=0, R=0 maintains the previous state
  • The S=1, R=1 input combination, which is typically undefined or forbidden for an SR latch, will continue to set Q=1, Q'=0 as per the previous behavior to maintain compatibility. This behavior is now explicitly documented in the code.

A new test suite, TestFlipFlop_SR_Latch_Logic, has been added to gate/flipflop_test.go to thoroughly verify the corrected SR latch functionality. These tests cover various input combinations, including the enable signal behavior and state maintenance, ensuring the gate behaves as expected. All new tests are passing.

The FlipFlop gate was previously implemented with D flip-flop behavior. This commit corrects the Handler function in `gate/flipflop.go` to implement the proper SR latch logic:
- S=1, R=0 sets Q=1, Q'=0
- S=0, R=1 sets Q=0, Q'=1
- S=0, R=0 maintains the previous state
- The S=1, R=1 input combination, which is typically undefined or forbidden for an SR latch, will continue to set Q=1, Q'=0 as per the previous behavior to maintain compatibility. This behavior is now explicitly documented in the code.

A new test suite, `TestFlipFlop_SR_Latch_Logic`, has been added to `gate/flipflop_test.go` to thoroughly verify the corrected SR latch functionality. These tests cover various input combinations, including the enable signal behavior and state maintenance, ensuring the gate behaves as expected. All new tests are passing.
@Ariyn Ariyn requested a review from Copilot June 3, 2025 14:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the FlipFlop gate logic so that it behaves as an SR latch rather than a D flip-flop, and it adds comprehensive tests for the corrected behavior.

  • Correct SR latch behavior is implemented in the Handler function.
  • A new test suite in gate/flipflop_test.go validates SR latch functionality under various input scenarios.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
gate/flipflop.go Updated Handler to implement proper SR latch logic and document S=1,R=1 behavior.
gate/flipflop_test.go Added extensive tests to verify SR latch logic and enable transitions.

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