Comments (2)
Hi Ben,
You are right. It has been well defined since C99. It was ANSI C (C89),
where it was let up to implementation (whether to truncate towards 0 or
upwards).
I think a bigger problem is the fact that in some languages "%" stands
either for modulo (e.g. in Python) or for the remainder (e.g. in C), the
difference being whether the sign of the result is the same as in the
second operand or as in the first and thus many programmers are a little
wary every time they see "/" or "%" anywhere near operands with different
signs.
Having said that, I agree that we can remove that particular editorial from
the spec :)
Happy hacking,
Vladimir
On Tue, Aug 16, 2016 at 3:19 PM, Ben Pfaff [email protected] wrote:
Section 10.6 says:
Division and modulo are illegal for negative values (the C language does
not give a clear semantics to division of signed integers when values are
negative).but this is incorrect. The ISO C standard for C, 2011 edition, defines
division clearly and unambigiously as the following in section 6.5.5
"Multiplicative operators" (this has only been clarified slightly since the
1999 edition):When integers are divided, the result of the / operator is the algebraic
quotient with any
fractional part discarded. 105) If the quotient a/b is representable, the
expression
(a/b)*b + a%b shall equal a; otherwise, the behavior of both a/b and a%b is
undefined.
105) This is often called ‘‘truncation toward zero’’.It's one thing if P4 doesn't want to define this but it shouldn't make
incorrect claims about the C language.Even if we don't want to define division for negative values, it's
probably best if P4 defines 0/x as zero instead of forbidding it.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#40, or mute the thread
https://github.com/notifications/unsubscribe-auth/AMPb8-PJimJ-UT-cBGe_BXbkxoB67oOaks5qgjePgaJpZM4Jl6Nh
.
from p4-spec.
I would be in favor of removing nearly all references to other languages from the P4-16 specification. It's fine to say in the preamble that the language is C-like, but it would be best if the specification was as self-contained as is practical. The current draft references ideas from C, C++, C#, and Java on many pages (I started marking them up as Word comments -- there are dozens of these). If we assume that the reader is intimately familiar with the dark corners of the specifications of these languages, we greatly increases the knowledge needed to understand P4, which is a real shame. Moreover, in many cases, the P4 construct is not precisely the same as in the language being referred to, so making an analogy is arguably more harmful than helpful.
from p4-spec.
Related Issues (20)
- Where should a `@hidden` annotation on an action be placed? HOT 3
- Clarification regarding Exit statement HOT 19
- L-Value Syntax HOT 3
- Clarification on the calling convention of directionless, extern parameter HOT 4
- Subtlety between length and size. HOT 3
- Missing code-block markup in section "Static assertions" HOT 1
- Allow compile-time resolvable expressions for switch labels? HOT 5
- Incomplete list of operators in compile-time known values section? HOT 1
- Modular match fields for tables. HOT 20
- The type nesting and typedef rules are not clear HOT 5
- Investigate whether PDF/HTML generated for all versions are in git repo history HOT 2
- Should identifiers declared with const be a local compile-time known value if their init expression is? HOT 8
- Should run-time variables that a sophisticated compiler can prove must be equal to a compile-time known value, be treated as a compile-time known value? HOT 2
- Document restriction that numeric priorities may not be specified within `const entries`
- Do we allow `string` type to be aliased by `typedef`? HOT 1
- Misleading code example for 8.24. Operations on types that are type variables
- Allow compile-time concatenation of strings HOT 1
- Consider AsciiDoc for future format of source for P4 language specification HOT 9
- CI: Create a CI job that builds the spec PDF and HTML for a PR
- Useful to create different bit slice variant that makes bit width easier to determine if it is compile time known? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p4-spec.