Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix negative modulo for C89 #45

Merged
merged 2 commits into from
May 21, 2019
Merged

Fix negative modulo for C89 #45

merged 2 commits into from
May 21, 2019

Conversation

bkthomps
Copy link
Owner

In C89, negative integer division and modulo is implementation-defined.

Case 1: division rounds to 0 (C89/90, C99, C11, C18)
-9 / 7 -> -1
-9 % 7 -> -2

Case 2: division rounds to negative infinity (C89/90)
-9 / 7 -> -2
-9 % 7 -> 5

This change fixes the deque data structure from having negative division and modulo to prevent this implementation-defined behavior.

Related to issue #44

bkthomps added 2 commits May 21, 2019 03:56
In C89, negative integer division and modulo is implementation defined.

There were cases of this in deque.c which have been fixed.
Have the C89 and non-C89 version of block calculations in the trim
function of deque follow the same logic. This will be slightly
slower, but it makes the code much cleaner and easier to maintain.
@bkthomps bkthomps added the compliance Anything which is not strictly-defined in all ISO/ANSI C standards label May 21, 2019
@bkthomps bkthomps self-assigned this May 21, 2019
@codecov-io
Copy link

codecov-io commented May 21, 2019

Codecov Report

Merging #45 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #45   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          16     16           
  Lines        2702   2704    +2     
=====================================
+ Hits         2702   2704    +2
Impacted Files Coverage Δ
src/deque.c 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b07e06d...df061e2. Read the comment docs.

@bkthomps bkthomps merged commit 411af13 into master May 21, 2019
@bkthomps bkthomps deleted the fix-negative-modulo branch May 21, 2019 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compliance Anything which is not strictly-defined in all ISO/ANSI C standards
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants