本文整理汇总了C++中mozilla::NumberEqualsInt32方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::NumberEqualsInt32方法的具体用法?C++ mozilla::NumberEqualsInt32怎么用?C++ mozilla::NumberEqualsInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::NumberEqualsInt32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: powi
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);
}
示例2: AtomizeString
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;
}