summaryrefslogtreecommitdiffstats
path: root/generic/tclStrToD.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-08 12:51:29 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-08 12:51:29 (GMT)
commit0df818c01fec80789e1b6b0e5182d5a321bcd171 (patch)
treecbaa9086b802260443c68afdf221cdeccec91d4a /generic/tclStrToD.c
parent6dcb4cb65c8f36fa851d95eca2a23fb580d82db2 (diff)
parent3b3abe0ce145a48c4426746f839aa29867e5991b (diff)
downloadtcl-0df818c01fec80789e1b6b0e5182d5a321bcd171.zip
tcl-0df818c01fec80789e1b6b0e5182d5a321bcd171.tar.gz
tcl-0df818c01fec80789e1b6b0e5182d5a321bcd171.tar.bz2
Use _copysign on Windows always (available from float.h). Use mp_iszero() whenever appropriate.
Diffstat (limited to 'generic/tclStrToD.c')
-rw-r--r--generic/tclStrToD.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index aafd282..b9026cd 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -15,18 +15,11 @@
#include "tclInt.h"
#include "tommath.h"
+#include <float.h>
#include <math.h>
-/*
- * Older MSVC has no copysign function, but it's available at least since
- * MSVC++ 12.0 (that is Visual Studio 2013).
- */
-
-#if (defined(_MSC_VER) && (_MSC_VER < 1800))
-inline static double
-copysign(double a, double b) {
- return _copysign(a, b);
-}
+#ifdef _WIN32
+#define copysign _copysign
#endif
/*
@@ -1299,7 +1292,7 @@ TclParseNumber(
case DECIMAL:
significandOverflow = AccumulateDecimalDigit(0, numTrailZeros-1,
&significandWide, &significandBig, significandOverflow);
- if (!significandOverflow && (significandWide > MOST_BITS+signum)){
+ if (!significandOverflow && (significandWide > MOST_BITS+signum)) {
significandOverflow = 1;
TclBNInitBignumFromWideUInt(&significandBig, significandWide);
}
@@ -1355,9 +1348,9 @@ TclParseNumber(
objPtr->typePtr = &tclDoubleType;
if (exponentSignum) {
- /*
+ /*
* At this point exponent>=0, so the following calculation
- * cannot underflow.
+ * cannot underflow.
*/
exponent = -exponent;
}
@@ -1383,7 +1376,7 @@ TclParseNumber(
}
}
- /*
+ /*
* The desired number is now significandWide * 10**exponent
* or significandBig * 10**exponent, depending on whether
* the significand has overflowed a wide int.
@@ -1410,7 +1403,7 @@ TclParseNumber(
#ifdef IEEE_FLOATING_POINT
case sNAN:
case sNANFINISH:
- objPtr->internalRep.doubleValue = MakeNaN(signum,significandWide);
+ objPtr->internalRep.doubleValue = MakeNaN(signum, significandWide);
objPtr->typePtr = &tclDoubleType;
break;
#endif
@@ -1906,7 +1899,7 @@ RefineApproximation(
/*
* Compute twoMv as 2*M*v, where v is the approximate value.
- * This is done by bit-whacking to calculate 2**(M2+1)*significand,
+ * This is done by bit-whacking to calculate 2**(M2+1)*significand,
* and then multiplying by 5**M5.
*/
@@ -1941,7 +1934,7 @@ RefineApproximation(
}
mp_mul_2d(&twoMd, M2+exponent+1, &twoMd);
- /*
+ /*
* Now let twoMd = twoMd - twoMv, the difference between the exact and
* approximate values.
*/
@@ -2009,7 +2002,7 @@ RefineApproximation(
}
}
- /*
+ /*
* Reduce the numerator and denominator of the corrector term so that
* they will fit in the floating point precision.
*/
@@ -4474,7 +4467,8 @@ TclInitDoubleConversion(void)
maxpow10_wide = (int)
floor(sizeof(Tcl_WideUInt) * CHAR_BIT * log(2.) / log(10.));
- pow10_wide = ckalloc((maxpow10_wide + 1) * sizeof(Tcl_WideUInt));
+ pow10_wide = (Tcl_WideUInt *)
+ ckalloc((maxpow10_wide + 1) * sizeof(Tcl_WideUInt));
u = 1;
for (i = 0; i < maxpow10_wide; ++i) {
pow10_wide[i] = u;
@@ -4802,7 +4796,7 @@ TclCeil(
mp_int d;
mp_init(&d);
mp_div_2d(a, -shift, &b, &d);
- exact = d.used == 0;
+ exact = mp_iszero(&d);
mp_clear(&d);
} else {
mp_copy(a, &b);