Skip to content

Commit 2573cbc

Browse files
committed
Use DBL_MIN as Number.MIN_VALUE if denormal numbers are not available
1 parent f3eb0a1 commit 2573cbc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

JavaScriptCore/runtime/NumberConstructor.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ NumberConstructor::NumberConstructor(JSGlobalObject* globalObject, Structure* st
6161
{
6262
}
6363

64+
static double MinValueAccountingForDenormals = DBL_MIN;
65+
6466
void NumberConstructor::finishCreation(ExecState* exec, NumberPrototype* numberPrototype)
6567
{
6668
Base::finishCreation(exec->globalData(), Identifier(exec, numberPrototype->s_info.className));
@@ -71,6 +73,14 @@ void NumberConstructor::finishCreation(ExecState* exec, NumberPrototype* numberP
7173

7274
// no. of arguments for constructor
7375
putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
76+
77+
// Test for denormal support. Use 5E-324 as MIN_VALUE if we have denormals
78+
// Careful: this test gets easily optimized away by the compiler, hence
79+
// the assignment to another var.
80+
double denormalTest = MinValueAccountingForDenormals / 2;
81+
if( denormalTest != 0 ) {
82+
MinValueAccountingForDenormals = 5E-324;
83+
}
7484
}
7585

7686
bool NumberConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
@@ -110,7 +120,7 @@ static JSValue numberConstructorMaxValue(ExecState*, JSValue, const Identifier&)
110120

111121
static JSValue numberConstructorMinValue(ExecState*, JSValue, const Identifier&)
112122
{
113-
return jsNumber(5E-324);
123+
return jsNumber(MinValueAccountingForDenormals);
114124
}
115125

116126
// ECMA 15.7.1

0 commit comments

Comments
 (0)