Commit c2e266f0 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Bug 930477: Implemented roundf for all platforms; r=waldo

parent c63a4cff
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4306,7 +4306,7 @@ CodeGenerator::visitMathFunctionF(LMathFunctionF *ins)
    void *funptr = nullptr;
    switch (ins->mir()->function()) {
      case MMathFunction::Floor: funptr = JS_FUNC_TO_DATA_PTR(void *, floorf);           break;
      case MMathFunction::Round: funptr = JS_FUNC_TO_DATA_PTR(void *, roundf); break;
      case MMathFunction::Round: funptr = JS_FUNC_TO_DATA_PTR(void *, math_roundf_impl); break;
      case MMathFunction::Ceil:  funptr = JS_FUNC_TO_DATA_PTR(void *, ceilf);            break;
      default:
        MOZ_ASSUME_UNREACHABLE("Unknown or unsupported float32 math function");
+19 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ using mozilla::Abs;
using mozilla::NumberEqualsInt32;
using mozilla::NumberIsInt32;
using mozilla::ExponentComponent;
using mozilla::FloatingPoint;
using mozilla::IsFinite;
using mozilla::IsInfinite;
using mozilla::IsNaN;
@@ -45,7 +46,6 @@ using mozilla::IsNegative;
using mozilla::IsNegativeZero;
using mozilla::PositiveInfinity;
using mozilla::NegativeInfinity;
using mozilla::SpecificNaN;
using JS::ToNumber;
using JS::GenericNaN;

@@ -745,17 +745,31 @@ js_math_random(JSContext *cx, unsigned argc, Value *vp)
double
js::math_round_impl(double x)
{
    int32_t i;
    if (NumberIsInt32(x, &i))
        return double(i);
    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) >= 52)
    if (ExponentComponent(x) >= int_fast16_t(FloatingPoint<double>::ExponentShift))
        return x;

    return js_copysign(floor(x + 0.5), x);
}

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);
}

bool /* ES5 15.8.2.15. */
js::math_round(JSContext *cx, unsigned argc, Value *vp)
{
+3 −0
Original line number Diff line number Diff line
@@ -265,6 +265,9 @@ math_round(JSContext *cx, unsigned argc, Value *vp);
extern double
math_round_impl(double x);

extern float
math_roundf_impl(float x);

extern double
powi(double x, int y);