Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Lustrec - public version
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LustreC
Lustrec - public version
Commits
a6e85cdc
Commit
a6e85cdc
authored
6 years ago
by
Pierre Loic Garoche
Browse files
Options
Downloads
Patches
Plain Diff
Integer div choices
parent
eccb3f63
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/integer_division.org
+45
-0
45 additions, 0 deletions
doc/integer_division.org
with
45 additions
and
0 deletions
doc/integer_division.org
0 → 100644
+
45
−
0
View file @
a6e85cdc
Integer division in LustreC
* Issue
Integer division / and associated modulo mod
a = (a / b) * b + (a mod b)
Division between two integers can be interpreted in different ways
- a C like division where sign(a mod b) = sign a
- a euclidean division where 0 <= a mod b < |b|
In both cases they satisfy the above equation.
Kind model-checker or Horn encoding assumes the mathematical definition, ie. the
euclidean division, while lustreC or the Verimag compiler rely on the C
definition.
In the following we deonote by div_C/mod_C and div_M/mod_M the functions in C
and math, respectively.
As an example -4 div_C 3 = -1 while -4 div_M 3 = 2
Some properties:
- we have a div_M b = a div_C b when a = b * k
- we have a mod_C b = 0 \equiv a mod_M b = 0.
* From C to Euclidian
a mod_M b = (a mod_C b) + (a < 0 ? abs(b) : 0)
a div_M b = (a - (a mod_M b)) div_C b
= (a - ((a mod_C b) + (a < 0 ? abs(b) : 0))) div_C b
* From Euclidian to C
a mod_C b = (a >= 0 ? a mod_M b : - ((-a) mod_M b))
(using math def to ensure positiveness of remainder))
= (a mod_M b) - (a < 0 ? abs(b) : 0)
(using the def of mod_M above)
a div_C b = (a - (a mod_C b)) div_M b
= (a - ((a mod_M b) - (a < 0 ? abs(b) : 0))) div_M b
Let's chosse the second, simpler, def of mod_C
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment