Bug 331362 - kcalc should not allow negative numbers of shift eg: 9 >> -1 or 9 << -1
Summary: kcalc should not allow negative numbers of shift eg: 9 >> -1 or 9 << -1
Status: RESOLVED INTENTIONAL
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Mint (Ubuntu based) Linux
: NOR normal
Target Milestone: ---
Assignee: Evan Teran
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-21 04:55 UTC by Raushan Kumar
Modified: 2019-07-10 21:41 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
generally negative number of shifts are not allowed ,so the output for negative numbers of shift I thought ,should be nan. (834 bytes, patch)
2014-02-21 04:55 UTC, Raushan Kumar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Raushan Kumar 2014-02-21 04:55:22 UTC
Created attachment 85256 [details]
generally negative number of shifts are not allowed ,so the output for negative numbers of shift I thought ,should be nan.

kcalc should not allow negative numbers of shift as separate buttons for left shift and right shifts are provided. And I searched and something relevant is :

http://www.miniwebtool.com/bitwise-calculator/bit-shift/?data_type=10&number=9&place=-1&operator=Shift+Left

and also  g++ compiler gives warning for negative number of shift eg: 9 << -1 and its answer according to g++ is:=-2147483648  which is unexpected and its due to operation on 64 bits.

I am attaching one of the possible solution for this bug. As generally negative number of shifts are not allowed ,so the output for negative numbers of shift I thought ,should be nan.
Comment 1 Evan Teran 2014-02-21 12:27:52 UTC
I am not sure that I would consider this a bug or something which needs fixing.

In kcalc a negative shift is simply considered to be a shift of the same magnitude in the opposite direction. kcalc's behavior is consistent and (at least to me) a reasonable interpretation of what the user asked to do.

So while other sources may choose to handle this differently, I don't know that one is absolutely "correct".
Comment 2 Andrew Crouthamel 2018-11-11 04:31:59 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 3 Andrew Crouthamel 2018-11-21 04:34:03 UTC
Dear Bug Submitter,

This is a reminder that this bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? This bug will be moved back to REPORTED Status for manual review later, which may take a while. If you are able to, please lend us a hand.

Thank you for helping us make KDE software even better for everyone!
Comment 4 Viorel-Cătălin Răpițeanu 2019-02-12 20:12:59 UTC
Negative shifts are still used in KCalc at this moment. A KCalc developer should analyze your patch and should check if there are any unintended effects introduced by it.
Comment 5 Christoph Feck 2019-07-10 21:41:24 UTC
Given that "a << b" can be mathematically defined as "a * 2^b", it works as intended.

The reason compilers forbid negative shifts is because CPU instruction sets handle left and right shifts separately.