summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authornijtmans <nijtmans>2010-02-21 08:56:19 (GMT)
committernijtmans <nijtmans>2010-02-21 08:56:19 (GMT)
commit5330abf13c39fb141897f214a8e8beaddb51a7f5 (patch)
tree647f1caa3c8ab23d87e432bd486d433d42528436 /generic/tclBasic.c
parent9f18dbce0e4a7064e46cf22f9950b5cb220f21a4 (diff)
downloadtcl-5330abf13c39fb141897f214a8e8beaddb51a7f5.zip
tcl-5330abf13c39fb141897f214a8e8beaddb51a7f5.tar.gz
tcl-5330abf13c39fb141897f214a8e8beaddb51a7f5.tar.bz2
Fix [Bug 2954959] expr abs(0.0) is -0.0
and added test cases for it.
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 0a191bb..527ed81 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -16,7 +16,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.444 2010/02/15 22:56:19 nijtmans Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.445 2010/02/21 08:56:19 nijtmans Exp $
*/
#include "tclInt.h"
@@ -7433,9 +7433,13 @@ ExprAbsFunc(
if (type == TCL_NUMBER_DOUBLE) {
double d = *((const double *) ptr);
+ static const double poszero = 0.0;
- if (d <= 0.0) {
- Tcl_SetObjResult(interp, Tcl_NewDoubleObj(-d));
+ /* We need to distinguish here between positive 0.0 and
+ * negative -0.0, see Bug ID #2954959.
+ */
+ if ((d <= -0.0) && memcmp(&d, &poszero, sizeof(double))) {
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(-d));
} else {
Tcl_SetObjResult(interp, objv[1]);
}