diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-08-17 22:15:49 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-08-17 22:15:49 (GMT) |
commit | 90afac281e7c26675e3a6816937db7794f49ceef (patch) | |
tree | 56921c8b8994af8d8a36ccbbc0ea11ac47da2bac /generic | |
parent | 6c78bf0adcb250437f1bb8dd19f13b7c2aa83848 (diff) | |
download | tcl-90afac281e7c26675e3a6816937db7794f49ceef.zip tcl-90afac281e7c26675e3a6816937db7794f49ceef.tar.gz tcl-90afac281e7c26675e3a6816937db7794f49ceef.tar.bz2 |
Minor fix to entier(): Allow it to convert to "wideInt" as well when range is appropriate
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclBasic.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 07f7e5c..e014b06 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -7606,7 +7606,19 @@ ExprEntierFunc( if (type == TCL_NUMBER_DOUBLE) { d = *((const double *) ptr); - if ((d >= (double)LONG_MAX) || (d <= (double)LONG_MIN)) { + if ((d < (double)LONG_MAX) && (d > (double)LONG_MIN)) { + long result = (long) d; + + Tcl_SetObjResult(interp, Tcl_NewLongObj(result)); + return TCL_OK; +#ifndef TCL_WIDE_INT_IS_LONG + } else if ((d < (double)LLONG_MAX) && (d > (double)LLONG_MIN)) { + Tcl_WideInt result = (Tcl_WideInt) d; + + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(result)); + return TCL_OK; +#endif + } else { mp_int big; if (Tcl_InitBignumFromDouble(interp, d, &big) != TCL_OK) { @@ -7615,11 +7627,6 @@ ExprEntierFunc( } Tcl_SetObjResult(interp, Tcl_NewBignumObj(&big)); return TCL_OK; - } else { - long result = (long) d; - - Tcl_SetObjResult(interp, Tcl_NewLongObj(result)); - return TCL_OK; } } |