double js::ecmaPow(double x, double y) { /* * Use powi if the exponent is an integer-valued double. We don't have to * check for NaN since a comparison with NaN is always false. */ int32_t yi; if (NumberEqualsInt32(y, &yi)) return powi(x, yi); /* * Because C99 and ECMA specify different behavior for pow(), * we need to wrap the libm call to make it ECMA compliant. */ if (!IsFinite(y) && (x == 1.0 || x == -1.0)) return GenericNaN(); /* pow(x, +-0) is always 1, even for x = NaN (MSVC gets this wrong). */ if (y == 0) return 1; /* * Special case for square roots. Note that pow(x, 0.5) != sqrt(x) * when x = -0.0, so we have to guard for this. */ if (IsFinite(x) && x != 0.0) { if (y == 0.5) return sqrt(x); if (y == -0.5) return 1.0 / sqrt(x); } return pow(x, y); }
bool HashableValue::setValue(JSContext* cx, HandleValue v) { if (v.isString()) { // Atomize so that hash() and operator==() are fast and infallible. JSString* str = AtomizeString(cx, v.toString(), DoNotPinAtom); if (!str) return false; value = StringValue(str); } else if (v.isDouble()) { double d = v.toDouble(); int32_t i; if (NumberEqualsInt32(d, &i)) { // Normalize int32_t-valued doubles to int32_t for faster hashing and testing. value = Int32Value(i); } else if (IsNaN(d)) { // NaNs with different bits must hash and test identically. value = DoubleNaNValue(); } else { value = v; } } else { value = v; } MOZ_ASSERT(value.isUndefined() || value.isNull() || value.isBoolean() || value.isNumber() || value.isString() || value.isSymbol() || value.isObject()); return true; }