Comments (7)
rev 198 fixes 15 << -2 = 3.75 issue.
Original comment by [email protected]
on 7 Feb 2013 at 12:45
from muparserx.
Moreover, MSDN states that << behavior is "undefined" if right operang is
non-positive, e.g. 15 << -2 results in undefined behavior. I think ecDOMAIN
could suit such an situation pretty well.
Original comment by [email protected]
on 7 Feb 2013 at 1:13
from muparserx.
Let me know your minds and i will implement then correct behavior:
1. right operand cannot be negativ -> ecDOMAIN
2. right operand is 0 -> left operand is returned
3. overflow detection which is done for << and >> does not need one.
Original comment by [email protected]
on 7 Feb 2013 at 1:16
from muparserx.
The short answer would be: Please take Mathematica (Wolfram alpha as a
reference), Matlab, Octave as a reference (all of them allow negative operands).
The more detailed Version is:
MSDN is refering to the C/C++ Standard. It merely means that the standard
doesn't say anything about how compiler vendors should treat negative operands
so they are free to do whatever they want. So a standard compliant
implementation of c++ is allowed to crash and burn your system if it sees a
negative operand. That doesn't necessarily make it a very good standard
compliant compiler as there is nothing intrinsicly undefined in the problem
itself.
I'd define the following set of requirements for shift operations that are as
universal as possible (given the constraint of not having arbitrary precision):
- Shift operations work only with integer values
- the return value of a shift operation must represent an integer value and
each digit of the return value must be known for sure as to allow conversion to
a binary number. If this can't be guaranteed (and only then) an overflow
exception should be raised.
- the operations a << b and a >> -b are equivalent
- the operations a >> b and a << -b are equivalent
- the first operand may be a negative number
Here is my reasoning for this:
From a human perspective negative operands are pretty useless but so is
shifting by 0 and if we forbade negative operands why not 0 too?. No human user
should shift a value to the left by -2 because well, that looks pretty stupid.
There is however nothing undefined to it i'm against imposing arbitrary
restrictions to the domain. muparserx may end up being the backend of an
application which may automatically generate expressions. Such an application
may automatically create expression like "a << b" and as b is a variable it may
end up being negative or even be required by an algorithm to be negative
assuming a negative operand will reverse the shifting direction. A thought that
is completely rational. If a domain error would be thrown despite being able to
provide a result the client code would needlessly have to work around this
issue.
Original comment by [email protected]
on 7 Feb 2013 at 5:26
from muparserx.
Okay, now we have that - sign behavior more-or-less correct, have you tried my
fix? it should work, works for me. :)
Original comment by [email protected]
on 7 Feb 2013 at 7:20
from muparserx.
Yes, seems to work in general but there was a minor issue left with shifting
negative values. I applied a minor fix in order to correct this. I think this
was the last problem here so applied the code th shr as well to make sure both
operators use the same logic.
Original comment by [email protected]
on 7 Feb 2013 at 8:12
from muparserx.
Original comment by [email protected]
on 8 Feb 2013 at 8:14
- Changed state: Fixed
from muparserx.
Related Issues (20)
- Tag for release 4.0.9 HOT 2
- Missing header HOT 1
- README says that the version is 4.0.9 but the last tag is 4.0.8 HOT 2
- how to switch rad or gra when use trigonometric function HOT 2
- Incorrect Assignment Multiplication HOT 1
- Inconsistent Use of Signedness for Binary and Hex Numbers
- Feature Request: Add an Octal Value Reader
- logic operator lack shor-circuit feature
- 4.0.10 FTBFS HOT 1
- constant starting with letter 'o' HOT 5
- Example fails on macOS HOT 7
- int to bool conversion HOT 3
- type checking HOT 1
- xor is listed in the documentation but not implemented HOT 3
- Is it possible to directly represent a matrix instead of using many lines to define it? HOT 4
- FunTan and FunSin error HOT 2
- Is matrix algebra in SetExpr possible? HOT 2
- fail at parsing boolean linear operation HOT 2
- [4.0.12] SEGFAULT in mupTokenReader
- Example couldn't be built on MINGW windows
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 muparserx.