https://bugs.kde.org/show_bug.cgi?id=503863

Gabriel Barrantes <gabriel.barrantes....@outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|evan.te...@gmail.com        |gabriel.barrantes.dev@outlo
                   |                            |ok.com
             Status|REPORTED                    |CONFIRMED

--- Comment #2 from Gabriel Barrantes <gabriel.barrantes....@outlook.com> ---
(In reply to Johannes from comment #1)
> I was poking around in the source code, it seems like the sequence of events
> leading to the bug is:
> 
> 1. Expression starting with - is encountered, and a leading zero is inserted
> to make the binary - operator happy (in `CalcEngine::calculate()`
> 2. Expression is evaluated backwards in `CalcEngine::reduce_Stack_`
> 
> I'm happy to submit a patch fixing it, but after debugging a little the
> right solution was no longer obvious. I see two possible approaches:
> 
> 1: Further modify the special case handling of first token being a
> `TokenCode::MINUS`  in `CalcEngine::calculate()` to ensure -number is always
> parsed as (-number). Which I think requires keeping state across
> iterations... which seems somewhat distasteful
> 2: Rewrite `CalcEngine` to support operators precedence and handle operators
> that can both be binary and unary. What I think is the _right_ solution and
> I'm happy to do so, but its a major refactor for a random drive-by patch.
> 
> I'm happy to do implement either (or just leave the problem for somebody
> else), but I need somebody to point me in the right direction first.

Hello Johannes, I am the developer of that code,
so, if you enter (- 58) >> 2 you get the expected -15, when I added all the
operators I pretty much decided (for convenience) that the binary operators
will take precedence over "unary left operators" and this is result of that, I
entered the same in other places (Qalculate, the C compiler) and seems to be
behaving like what you are expecting, implementing this would not be easy tho,
if you want to work in this open an issue in the git repo so we can discuss how
to approach it.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to