Tcl Source Code

Artifact [c52730bdd7]
Login

Artifact c52730bdd776ea980fd54c3c4e58f683b1fcf992:

Attachment "wideRound.patch" to ticket [908375ffff] added by dkf 2004-03-30 05:04:12.
Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.121
diff -u -r1.121 tclExecute.c
--- generic/tclExecute.c	18 Jan 2004 16:19:05 -0000	1.121
+++ generic/tclExecute.c	29 Mar 2004 21:47:01 -0000
@@ -5704,15 +5704,12 @@
 {
     register Tcl_Obj **tosPtr;	/* Cached pointer to top of evaluation stack. */
     Tcl_Obj *valuePtr;
-    long iResult;
-    double d, temp;
-    int result;
+    int result = TCL_OK;
 
     /*
      * Set stackPtr and stackTop from eePtr.
      */
 
-    result = TCL_OK;
     CACHE_STACK_INFO();
 
     /*
@@ -5727,16 +5724,17 @@
     }
     
     if (valuePtr->typePtr == &tclIntType) {
-	iResult = valuePtr->internalRep.longValue;
+	PUSH_OBJECT(Tcl_NewLongObj(valuePtr->internalRep.longValue));
     } else if (valuePtr->typePtr == &tclWideIntType) {
 	Tcl_WideInt w;
-	TclGetWide(w,valuePtr);
+
+	TclGetWide(w, valuePtr);
 	PUSH_OBJECT(Tcl_NewWideIntObj(w));
-	goto done;
     } else {
-	d = valuePtr->internalRep.doubleValue;
+	double temp, d = valuePtr->internalRep.doubleValue;
+
 	if (d < 0.0) {
-	    if (d <= (((double) (long) LONG_MIN) - 0.5)) {
+	    if (d <= Tcl_WideAsDouble(LLONG_MIN)-0.5) {
 		tooLarge:
 		Tcl_ResetResult(interp);
 		Tcl_AppendToObj(Tcl_GetObjResult(interp),
@@ -5747,28 +5749,22 @@
 		result = TCL_ERROR;
 		goto done;
 	    }
-	    temp = (long) (d - 0.5);
+	    temp = Tcl_DoubleAsWide(d - 0.5);
 	} else {
-	    if (d >= (((double) LONG_MAX + 0.5))) {
+	    if (d >= Tcl_WideAsDouble(LLONG_MAX)+0.5) {
 		goto tooLarge;
 	    }
-	    temp = (long) (d + 0.5);
+	    temp = Tcl_DoubleAsWide(d + 0.5);
 	}
 	if (IS_NAN(temp) || IS_INF(temp)) {
 	    TclExprFloatError(interp, temp);
 	    result = TCL_ERROR;
 	    goto done;
 	}
-	iResult = (long) temp;
+	PUSH_OBJECT(Tcl_NewWideIntObj(Tcl_DoubleAsWide(temp)));
     }
 
     /*
-     * Push a Tcl object with the result.
-     */
-    
-    PUSH_OBJECT(Tcl_NewLongObj(iResult));
-
-    /*
      * Reflect the change to stackTop back in eePtr.
      */