本文整理汇总了C++中mozilla::ExponentComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::ExponentComponent方法的具体用法?C++ mozilla::ExponentComponent怎么用?C++ mozilla::ExponentComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::ExponentComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CallArgsFromVp
JSBool /* ES5 15.8.2.15. */
js_math_round(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() == 0) {
args.rval().setDouble(js_NaN);
return true;
}
double x;
if (!ToNumber(cx, args[0], &x))
return false;
int32_t i;
if (DoubleIsInt32(x, &i)) {
args.rval().setInt32(i);
return true;
}
/* Some numbers are so big that adding 0.5 would give the wrong number. */
if (ExponentComponent(x) >= 52) {
args.rval().setNumber(x);
return true;
}
args.rval().setNumber(js_copysign(floor(x + 0.5), x));
return true;
}
示例2: js_copysign
float
js::math_roundf_impl(float x)
{
int32_t ignored;
if (NumberIsInt32(x, &ignored))
return x;
/* Some numbers are so big that adding 0.5 would give the wrong number. */
if (ExponentComponent(x) >= int_fast16_t(FloatingPoint<float>::ExponentShift))
return x;
return js_copysign(floorf(x + 0.5f), x);
}
示例3: double
double
js::math_round_impl(double x)
{
int32_t i;
if (DoubleIsInt32(x, &i))
return double(i);
/* Some numbers are so big that adding 0.5 would give the wrong number. */
if (ExponentComponent(x) >= 52)
return x;
return js_copysign(floor(x + 0.5), x);
}
示例4: js_copysign
double
js::math_round_impl(double x)
{
int32_t ignored;
if (NumberIsInt32(x, &ignored))
return x;
/* Some numbers are so big that adding 0.5 would give the wrong number. */
if (ExponentComponent(x) >= int_fast16_t(FloatingPoint<double>::kExponentShift))
return x;
double add = (x >= 0) ? GetBiggestNumberLessThan(0.5) : 0.5;
return js_copysign(floor(x + add), x);
}
示例5:
static void
TestExponentComponent()
{
MOZ_ASSERT(ExponentComponent(0.0) == -int_fast16_t(DoubleExponentBias));
MOZ_ASSERT(ExponentComponent(-0.0) == -int_fast16_t(DoubleExponentBias));
MOZ_ASSERT(ExponentComponent(0.125) == -3);
MOZ_ASSERT(ExponentComponent(0.5) == -1);
MOZ_ASSERT(ExponentComponent(1.0) == 0);
MOZ_ASSERT(ExponentComponent(1.5) == 0);
MOZ_ASSERT(ExponentComponent(2.0) == 1);
MOZ_ASSERT(ExponentComponent(7) == 2);
MOZ_ASSERT(ExponentComponent(PositiveInfinity()) == DoubleExponentBias + 1);
MOZ_ASSERT(ExponentComponent(NegativeInfinity()) == DoubleExponentBias + 1);
MOZ_ASSERT(ExponentComponent(UnspecifiedNaN()) == DoubleExponentBias + 1);
}