KJS::SimpleNumber on 64 bit machines
Harri Porten
porten at froglogic.com
Thu Oct 2 00:57:50 CEST 2003
On Wed, 1 Oct 2003, Maciej Stachowiak wrote:
> I think this patch will fix it, but I don't have a 64-bit platform to
> test on. Could you try it? It shuts up the warnings and also uses all
> 64 bits (which is not really required but seems nice).
I added to L's to the 1 constants to avoid two warnings about the shift
exceeding the types range.
< enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1 <<
31, max = (1 << (31 - shift)) - 1, min = -max - 1 };
---
> enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1L <<
(sizeof(long) * 8 - 1 ), max = (1L << ((sizeof(long) * 8 - 1) - shift)) -
1, min = -max - 1 };
Now there are two warnings left because fits(int) will now always return
true on 64-bit machines but this is indeed harmless and I'll leave this to
owners of 64 bit machines to fix.
I noticed that our fits(double) code is different to yours (the patch
didn't apply cleanly). Peter, could you comment on the
IS_NEGATIVE_ZERO() check ? Something that Apple should be using, too ?
I've also applied other patches to avoid running into NaN in the code
path. You might want to use them two to let our code base not drift
further apart.
This one really makes sense (there is no need for a signed NaN):
--- ustring.cpp 11 Jun 2003 17:28:01 -0000 1.59
+++ ustring.cpp 1 Oct 2003 21:54:28 -0000 1.60
@@ -650,8 +650,8 @@ double UString::toDouble( bool tolerant
while (isspace(*c))
c++;
// don't allow anything after - unless tolerant=true
- if ( !tolerant && *c != '\0')
- d = NaN;
+ if (!tolerant && *c != '\0')
+ return NaN;
return d*sign;
}
These three are according to the spec's calculation and also nuke a
TODO. If the additional function calls are an issue we could ifdef those
with __alpha.
diff -u -3 -p -r1.165 -r1.167
--- internal.cpp 27 Sep 2003 19:24:28 -0000 1.165
+++ internal.cpp 1 Oct 2003 21:18:37 -0000 1.167
@@ -992,7 +992,9 @@ double KJS::roundValue(ExecState *exec,
if (v.type() == UndefinedType) /* TODO: see below */
return 0.0;
double n = v.toNumber(exec);
- if (n == 0.0) /* TODO: -0, NaN, Inf */
+ if (isNaN(n))
+ return NaN;
+ if (n == 0.0) /* TODO: -0, Inf */
return 0.0;
double d = floor(fabs(n));
if (n < 0)
--- value.cpp 1 Oct 2003 20:53:01 -0000 1.31
+++ value.cpp 1 Oct 2003 21:10:07 -0000
@@ -109,6 +109,8 @@ int ValueImp::toInt32(ExecState *exec) c
return (int)i;
double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
+ if (isNaN(d) || isInf(d) || d == 0.0)
+ return 0;
double d32 = fmod(d, D32);
//Make sure we use the positive remainder. This matters since this may
be
@@ -129,6 +131,8 @@ unsigned int ValueImp::toUInt32(ExecStat
return i;
double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
+ if (isNaN(d) || isInf(d) || d == 0.0)
+ return 0;
double d32 = fmod(d, D32);
return static_cast<unsigned int>(d32);
Harri.
More information about the Khtml-devel
mailing list