After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 332023 - Problems with Bitwise Operators
Problems with Bitwise Operators
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
5.6.x
Other All
: High normal
: ---
Assigned To: Sami Pietilä
Rich Burridge
Depends on:
Blocks:
 
 
Reported: 2006-02-21 12:15 UTC by Daniel Holbach
Modified: 2006-03-28 21:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The Fix. (4.35 KB, patch)
2006-03-02 23:20 UTC, Sami Pietilä
none Details | Review

Description Daniel Holbach 2006-02-21 12:15:45 UTC
Forwarded from: https://launchpad.net/distros/ubuntu/+source/gcalctool/+bug/32200

The bitwise operators don't work when you use them with the result of a previous operation:

2 And 3 =
2

Leave the two there and press
Or 5 =

results in a malformed expression, while it should probably say 7.

My version is 5.6.31.
Comment 1 Rich Burridge 2006-02-27 16:14:21 UTC
I've just tested this with gcalctool v5.7.29.
It does the correct thing (answer 7) in 
non-arithmetic operator precedence mode, but fails
as you report, in arithmetic precedence mode.

Transferring to Sami for further investigation.
Comment 2 Sami Pietilä 2006-02-27 20:34:29 UTC
This is a known issue. The explanation is that binary operators work only with integers and parser doesn't know if previous result is an integer (it could be a decimal number). Thus, parser does not allow the result of the previous calculation to be a parameter of an bitwise operation.

However, there could be a way to change this. One approach would be for the arithmetic operation to do the check. I would need a IS_INTEGER() function in order to do the check, 

where

boolean IS_INTEGER(a[MP_SIZE]) would return true or false depending if the parameter is an interger or not.
Comment 3 Rich Burridge 2006-02-27 20:59:57 UTC
I'd like the arithmetic precedence mode to be as similar to the 
non-aritmetic precedence mode as possible, so please implement
this. It's too later for GNOME 2.14, but it should go in for GNOME
2.15/16.

The set_bit_panel() routine in gtk.c does a test like this for
whether the bit panel items should be active or not. You're
going to need something like:

boolean
IS_INTEGER(int MPNUM[MP_SIZE])
{    
    int MPI[MPSIZE], MP2[MP_SIZE];

    MPstr_to_num(MPNUM, v->base, MP1);
    mpcmim(MP1, MP2);

    return(mpeq(MP1, MP2));
}
Comment 4 Sami Pietilä 2006-03-02 23:20:34 UTC
Created attachment 60521 [details] [review]
The Fix.

Thanks for the IS_INTEGER!

Using that, I made a patch, which hopefully fixes the problem.
Comment 5 Rich Burridge 2006-03-03 15:41:34 UTC
Thanks Sami. As we are fast approaching the GNOME 2.14 hard freeze,
I'll have a look at it once I've branched and apply it for GNOME 2.15/16.
Comment 6 Daniel Holbach 2006-03-03 15:49:21 UTC
Is the patch too intrusive to apply it before hard freeze? (I'm by no means pushing you, just curious.)
Comment 7 Rich Burridge 2006-03-03 15:55:23 UTC
Unfortunately the changes introduce  a new string and we went past the string
freeze on February 13th.
Comment 8 Sami Pietilä 2006-03-03 22:01:31 UTC
The fix is applicable even without the string change. However, the patch changes quite a bit how the parser deals with bitwise operations. 

The patch actually simplifies the parser.

I am not actually sure what kind of changes are allowed to gnome 2.14.1, but this patch would be a good candidate.
Comment 9 Rich Burridge 2006-03-28 19:24:05 UTC
Changes checked into CVS HEAD. Version number in configure.in
bumped to 5.8.5.
Comment 10 Daniel Holbach 2006-03-28 19:34:11 UTC
Does 5.8.5 mean that's GNOME 2.15 material?
Comment 11 Rich Burridge 2006-03-28 20:07:06 UTC
Yes. As there are string changes in this fix, I don't believe it's 
acceptable to apply it to a 2.14 "dot" release.
Comment 12 Daniel Holbach 2006-03-28 21:58:41 UTC
Thanks a lot. I will pass on the message.