From 59ee2f1e347fb19a9228787a2fc637dbff1d875c Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 10 Mar 2008 16:18:50 +0000 Subject: * generic/tclBasic.c (ExprAbsFunc): Revised so that the abs() * tests/expr.test: function and the [::tcl::mathfunc::abs] command do not return the value of -0, or equivalent values with more alarming string reps like -1e-350. [Bug 1893815]. --- ChangeLog | 7 +++++++ generic/tclBasic.c | 6 +++--- tests/expr.test | 20 +++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 732fa60..b3a0b94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-03-10 Don Porter + + * generic/tclBasic.c (ExprAbsFunc): Revised so that the abs() + * tests/expr.test: function and the [::tcl::mathfunc::abs] + command do not return the value of -0, or equivalent values with + more alarming string reps like -1e-350. [Bug 1893815]. + 2008-03-07 Andreas Kupries * generic/tclResult.c (ReleaseKeys): Workaround for [Bug diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 48e7059..b7f3423 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -14,7 +14,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.293 2008/02/29 19:59:59 dgp Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.294 2008/03/10 16:18:54 dgp Exp $ */ #include "tclInt.h" @@ -5963,7 +5963,7 @@ ExprAbsFunc( if (type == TCL_NUMBER_LONG) { long l = *((const long *) ptr); - if (l < (long)0) { + if (l <= (long)0) { if (l == LONG_MIN) { TclBNInitBignumFromLong(&big, l); goto tooLarge; @@ -5977,7 +5977,7 @@ ExprAbsFunc( if (type == TCL_NUMBER_DOUBLE) { double d = *((const double *) ptr); - if (d < 0.0) { + if (d <= 0.0) { Tcl_SetObjResult(interp, Tcl_NewDoubleObj(-d)); } else { Tcl_SetObjResult(interp, objv[1]); diff --git a/tests/expr.test b/tests/expr.test index 0ee024c..d0aaadb 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: expr.test,v 1.71 2007/12/13 15:26:06 dgp Exp $ +# RCS: @(#) $Id: expr.test,v 1.72 2008/03/10 16:18:55 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 @@ -6342,6 +6342,24 @@ test expr-37.14 {expr edge cases} {wideIs64bit} { test expr-38.1 {abs of smallest 32-bit integer [Bug 1241572]} {wideIs64bit} { expr {abs(-2147483648)} } 2147483648 +test expr-38.2 {abs and -0 [Bug 1893815]} { + expr {abs(-0)} +} 0 +test expr-38.3 {abs and -0 [Bug 1893815]} { + expr {abs(-0.0)} +} 0.0 +test expr-38.4 {abs and -0 [Bug 1893815]} { + expr {abs(-1e-324)} +} 0.0 +test expr-38.5 {abs and -0 [Bug 1893815]} { + ::tcl::mathfunc::abs -0 +} 0 +test expr-38.6 {abs and -0 [Bug 1893815]} { + ::tcl::mathfunc::abs -0.0 +} 0.0 +test expr-38.7 {abs and -0 [Bug 1893815]} { + ::tcl::mathfunc::abs -1e-324 +} 0.0 testConstraint testexprlongobj [llength [info commands testexprlongobj]] testConstraint testexprdoubleobj [llength [info commands testexprdoubleobj]] -- cgit v0.12