Bug 133420 - kcalc cmp function only compliments lower 32-bits
Summary: kcalc cmp function only compliments lower 32-bits
Status: RESOLVED FIXED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Klaus Niederkrüger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-02 04:32 UTC by Evan Teran
Modified: 2006-09-19 11:46 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Teran 2006-09-02 04:32:05 UTC
Version:           2.0.4 (using KDE 3.5.4, Gentoo)
Compiler:          Target: i686-pc-linux-gnu
OS:                Linux (i686) release 2.6.17-gentoo-r7

kcalc cmp function only compliments lower 32-bits. Basically kcalc has supported > 32-bits for a while, it seems that CMP is a function is did not transition correctly.

steps to reproduce:

open kcalc
set to hex mode
enter: FFFFFFFFFFFFFFFF
hit cmp
result is: FFFFFFFF00000000
should be: 0000000000000000

hitting cmp again confirms the behaviour by toggling the lower 32-bits back to F's

I recognize that since kcalc now attempts aribtrary precision, defining cmp is tough (how many F's to we append to the end since a positive nubmer basically has infinite 0's...)

Well the "correct" solution is not to litterally compliment, but instead take advantage of 2's compliment notation:

CMP in 2's compliment is exactly equivalent to negating the value then subtracting 1

for example:


4d2 hex (1234 in decimal) has the following value when complimented:
0xFFFFFFFFFFFFFB2D (-1235 in decimal)

so to properly implement CMP with arbitrary precision, simply negate the value, then subtract one from that. Obviously the result will be truncated in HEX view since that mode can only display 64-bits, but it will be correct. This should work correctly regardless of the number of bits supported and is trivial to implement.

Evan Teran
Comment 1 Evan Teran 2006-09-02 04:36:31 UTC
in a related bug: kcalc can be made to display "nan" with a cmp operation (no reason why this should be).

steps to reproduce:

open kcalc
set to decimal
enter: 1235
hit the inverse sign button
switch to hex mode (display now shows 0xFFFFFFFFFFFFFB2D)
switch to decimal mode (display now shows -1235)
hit cmp display shows "nan" should be 1234

Evan Teran
Comment 2 Klaus Niederkrüger 2006-09-17 13:12:12 UTC
Hi Evan,

Thank you very much for reporting again a bug (and for providing a solution).
I believe I have fixed this now in the cvs-trunk (both for KDE-3.5.5 and for KDE-4.0). I hope the time will arrive, when Hex will finally work without any bug in KCalc. :-(

Best

Klaus
Comment 3 Klaus Niederkrüger 2006-09-19 11:46:49 UTC
Seems to be fixed.
Klaus