Skip to content

Commit

Permalink
Fix Number.MIN_VALUE when denormal support is disabled for the CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Nov 5, 2013
1 parent ee9d2ce commit 850e642
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion JavaScriptCore/runtime/NumberConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ NumberConstructor::NumberConstructor(VM& vm, Structure* structure)
{
}

static double MinValueAccountingForDenormals = DBL_MIN;

void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)
{
Base::finishCreation(vm, NumberPrototype::info()->className);
Expand All @@ -70,6 +72,14 @@ void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)

// no. of arguments for constructor
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);

// Test for denormal support. Use 5E-324 as MIN_VALUE if we have denormals
// Careful: this test gets easily optimized away by the compiler, hence
// the assignment to another var.
double denormalTest = MinValueAccountingForDenormals / 2;
if( denormalTest != 0 ) {
MinValueAccountingForDenormals = 5E-324;
}
}

bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
Expand Down Expand Up @@ -104,7 +114,7 @@ static JSValue numberConstructorMaxValue(ExecState*, JSValue, PropertyName)

static JSValue numberConstructorMinValue(ExecState*, JSValue, PropertyName)
{
return jsNumber(5E-324);
return jsNumber(MinValueAccountingForDenormals);
}

// ECMA 15.7.1
Expand Down

0 comments on commit 850e642

Please sign in to comment.