Tk Source Code

View Ticket
Login
Ticket UUID: 220665
Title: bad scale RoundToResolution numerics
Type: Bug Version: obsolete: 8.3b2
Submitter: welch Created on: 2000-10-31 23:48:21
Subsystem: 15. [scale] Assigned To: nobody
Priority: 2 Severity:
Status: Closed Last Modified: 2001-03-24 04:30:19
Resolution: Fixed Closed By: dgp
    Closed on: 2001-03-23 21:30:19
Description:
OriginalBugID: 4099 Bug
Version: 8.3b2
SubmitDate: '2000-01-27'
LastModified: '2000-01-29'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 3689
OS: All
FixedDate: '2000-01-29'


Name:

Don Porter



Comments:

In floating point arithmetic, it may not be true that

    

    (N + 1) * delta == N * delta + delta



ReproducibleScript:

# FILE demo.tcl

pack [scale .s -length 441 -orient horizontal -resolution 0.5050838956 \

-from 463.667016161 -to 563.67362749 -digits 18]

.s set 513.7



ObservedBehavior:

$ wish demo.tcl



Wave the mouse over the scale and watch the

value and the slider "shake".



DesiredBehavior:

Scale should hold its value.



Patch:

Index: generic/tkScale.c

===================================================================

RCS file: /cvsroot/tk/generic/tkScale.c,v

retrieving revision 1.10

diff -c -r1.10 tkScale.c

*** tkScale.c   1999/12/22 20:01:07     1.10

--- tkScale.c   2000/01/27 22:41:38

***************

*** 1147,1166 ****

      TkScale *scalePtr;                /* Information about scale widget. */

      double value;             /* Value to round. */

  {

!     double rem, new;

  

      if (scalePtr->resolution <= 0) {

        return value;

      }

!     new = scalePtr->resolution * floor(value/scalePtr->resolution);

      rem = value - new;

      if (rem < 0) {

        if (rem <= -scalePtr->resolution/2) {

!           new -= scalePtr->resolution;

        }

      } else {

        if (rem >= scalePtr->resolution/2) {

!           new += scalePtr->resolution;

        }

      }

      return new;

--- 1147,1167 ----

      TkScale *scalePtr;                /* Information about scale widget. */

      double value;             /* Value to round. */

  {

!     double rem, new, tick;

  

      if (scalePtr->resolution <= 0) {

        return value;

      }

!     tick = floor(value/scalePtr->resolution);

!     new = scalePtr->resolution * tick;

      rem = value - new;

      if (rem < 0) {

        if (rem <= -scalePtr->resolution/2) {

!           new = (tick - 1.0) * scalePtr->resolution;

        }

      } else {

        if (rem >= scalePtr->resolution/2) {

!           new = (tick + 1.0) * scalePtr->resolution;

        }

      }

      return new;



PatchFiles:

generic/tkScale.c





Patch added to 8.3.0, also fixed resolution rounding bug in 3689. 
-- 01/29/2000 hobbs