summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2002-04-22 12:45:48 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2002-04-22 12:45:48 (GMT)
commit583fccf7dacaca22ab10188f000498427a7b0b6b (patch)
treedeba59bef17d328c7981202319ad045043ffe3c4 /generic
parentef9179154fce0934c48c8b1ecbb0a9323def847a (diff)
downloadtk-583fccf7dacaca22ab10188f000498427a7b0b6b.zip
tk-583fccf7dacaca22ab10188f000498427a7b0b6b.tar.gz
tk-583fccf7dacaca22ab10188f000498427a7b0b6b.tar.bz2
Fix for Bug 223739 to get rid of floating point equality test.
Sorry for delaying this fix for months; I hadn't noticed that it had been reviewed!
Diffstat (limited to 'generic')
-rw-r--r--generic/tkTextDisp.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index e0d1d57..2a3cf44 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkTextDisp.c,v 1.9 2000/01/06 02:18:59 hobbs Exp $
+ * RCS: @(#) $Id: tkTextDisp.c,v 1.10 2002/04/22 12:45:49 dkf Exp $
*/
#include "tkPort.h"
@@ -96,6 +96,16 @@ typedef struct TextStyle {
&& ((s1)->sValuePtr->bgStipple == (s2)->sValuePtr->bgStipple))
/*
+ * The following macro is used to compare two floating-point numbers
+ * to within a certain degree of scale. Direct comparison fails on
+ * processors where the processor and memory representations of FP
+ * numbers of a particular precision is different (e.g. Intel)
+ */
+
+#define FP_EQUAL_SCALE(double1, double2, scaleFactor) \
+ (fabs((double1)-(double2))*((scaleFactor)+1.0) < 0.3)
+
+/*
* The following structure describes one line of the display, which may
* be either part or all of one line of the text.
*/
@@ -3865,7 +3875,7 @@ GetXView(interp, textPtr, report)
* scrollbar if it has changed. */
{
TextDInfo *dInfoPtr = textPtr->dInfoPtr;
- char buffer[TCL_DOUBLE_SPACE * 2];
+ char buffer[TCL_DOUBLE_SPACE * 2 + 1];
double first, last;
int code;
@@ -3886,7 +3896,8 @@ GetXView(interp, textPtr, report)
Tcl_SetResult(interp, buffer, TCL_VOLATILE);
return;
}
- if ((first == dInfoPtr->xScrollFirst) && (last == dInfoPtr->xScrollLast)) {
+ if (FP_EQUAL_SCALE(first, dInfoPtr->xScrollFirst, dInfoPtr->maxLength) &&
+ FP_EQUAL_SCALE(last, dInfoPtr->xScrollLast, dInfoPtr->maxLength)) {
return;
}
dInfoPtr->xScrollFirst = first;
@@ -3936,7 +3947,7 @@ GetYView(interp, textPtr, report)
* scrollbar if it has changed. */
{
TextDInfo *dInfoPtr = textPtr->dInfoPtr;
- char buffer[TCL_DOUBLE_SPACE * 2];
+ char buffer[TCL_DOUBLE_SPACE * 2 + 1];
double first, last;
DLine *dlPtr;
int totalLines, code, count;
@@ -3971,7 +3982,8 @@ GetYView(interp, textPtr, report)
Tcl_SetResult(interp, buffer, TCL_VOLATILE);
return;
}
- if ((first == dInfoPtr->yScrollFirst) && (last == dInfoPtr->yScrollLast)) {
+ if (FP_EQUAL_SCALE(first, dInfoPtr->yScrollFirst, totalLines) &&
+ FP_EQUAL_SCALE(last, dInfoPtr->yScrollLast, totalLines)) {
return;
}
dInfoPtr->yScrollFirst = first;