Giter Club home page Giter Club logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
rev 198 fixes 15 << -2 = 3.75 issue.

Original comment by [email protected] on 7 Feb 2013 at 12:45

from muparserx.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024

Original comment by [email protected] on 8 Feb 2013 at 8:14

  • Changed state: Fixed

from muparserx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.