Bug 858131 - rewrite FloatingPoint.h to be C++-only instead of C-compatible C++; r+original-author=Waldo
authorNathan Froyd <froydnj@mozilla.com>
Wed, 01 May 2013 16:55:13 -0400
changeset 142333 cec949998373ea6396af7faa8496f62e8ab579da
parent 142332 c460bded7a668a2b6ff4af1dea51203e61b8c5a5
child 142334 fc6cc1be141653cbe546b29f43ff09814bd80b8f
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs858131
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 858131 - rewrite FloatingPoint.h to be C++-only instead of C-compatible C++; r+original-author=Waldo
content/html/content/src/HTMLInputElement.cpp
content/html/content/src/HTMLInputElement.h
content/media/AudioEventTimeline.h
content/media/MediaDecoder.cpp
content/media/webaudio/WebAudioUtils.h
content/media/webaudio/blink/DynamicsCompressorKernel.cpp
content/xslt/src/base/txDouble.cpp
content/xslt/src/xpath/txCoreFunctionCall.cpp
content/xslt/src/xpath/txNumberExpr.cpp
content/xslt/src/xpath/txNumberResult.cpp
content/xslt/src/xpath/txUnionNodeTest.cpp
content/xslt/src/xslt/txEXSLTFunctions.cpp
content/xslt/src/xslt/txFormatNumberFunctionCall.cpp
content/xslt/src/xslt/txStylesheet.cpp
content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
content/xslt/src/xslt/txXPathResultComparator.cpp
content/xslt/src/xslt/txXSLTNumber.cpp
content/xslt/src/xslt/txXSLTPatterns.cpp
dom/bindings/BindingUtils.cpp
dom/bindings/Codegen.py
dom/bindings/PrimitiveConversions.h
dom/indexedDB/Key.cpp
gfx/thebes/gfxFont.cpp
js/public/Value.h
js/src/builtin/Intl.cpp
js/src/builtin/MapObject.cpp
js/src/ctypes/CTypes.cpp
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/FoldConstants.cpp
js/src/frontend/ParseNode.cpp
js/src/ion/AsmJSLink.cpp
js/src/ion/RangeAnalysis.cpp
js/src/ion/RangeAnalysis.h
js/src/ion/x86/CodeGenerator-x86.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsarray.cpp
js/src/jsclone.cpp
js/src/jsdate.cpp
js/src/jsinterp.cpp
js/src/jslibmath.h
js/src/jsmath.cpp
js/src/jsnum.cpp
js/src/jsnum.h
js/src/json.cpp
js/src/jsstr.cpp
js/src/jstypedarray.cpp
js/src/methodjit/StubCalls.cpp
js/src/vm/DateTime.cpp
js/src/vm/DateTime.h
js/src/vm/NumericConversions.h
js/xpconnect/src/dictionary_helper_gen.py
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
layout/style/nsStyleAnimation.cpp
mfbt/FloatingPoint.h
mfbt/decimal/moz-decimal-utils.h
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -1182,17 +1182,17 @@ HTMLInputElement::ConvertStringToNumber(
     case NS_FORM_INPUT_DATE:
       {
         uint32_t year, month, day;
         if (!GetValueAsDate(aValue, &year, &month, &day)) {
           return false;
         }
 
         double date = JS::MakeDate(year, month - 1, day);
-        if (MOZ_DOUBLE_IS_NaN(date)) {
+        if (IsNaN(date)) {
           return false;
         }
 
         aResultValue = Decimal::fromDouble(date);
         return true;
       }
     case NS_FORM_INPUT_TIME:
       uint32_t milliseconds;
@@ -1356,19 +1356,17 @@ HTMLInputElement::ConvertNumberToString(
       {
         // The specs (and our JS APIs) require |aValue| to be truncated.
         aValue = aValue.floor();
 
         double year = JS::YearFromTime(aValue.toDouble());
         double month = JS::MonthFromTime(aValue.toDouble());
         double day = JS::DayFromTime(aValue.toDouble());
 
-        if (MOZ_DOUBLE_IS_NaN(year) ||
-            MOZ_DOUBLE_IS_NaN(month) ||
-            MOZ_DOUBLE_IS_NaN(day)) {
+        if (IsNaN(year) || IsNaN(month) || IsNaN(day)) {
           return false;
         }
 
         aResultString.AppendPrintf("%04.0f-%02.0f-%02.0f", year,
                                    month + 1, day);
 
         return true;
       }
@@ -1469,17 +1467,17 @@ HTMLInputElement::GetValueAsNumber(doubl
   return NS_OK;
 }
 
 void
 HTMLInputElement::SetValueAsNumber(double aValueAsNumber, ErrorResult& aRv)
 {
   // TODO: return TypeError when HTMLInputElement is converted to WebIDL, see
   // bug 825197.
-  if (MOZ_DOUBLE_IS_INFINITE(aValueAsNumber)) {
+  if (IsInfinite(aValueAsNumber)) {
     aRv.Throw(NS_ERROR_INVALID_ARG);
     return;
   }
 
   if (!DoesValueAsNumberApply()) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
@@ -3438,17 +3436,17 @@ HTMLInputElement::SanitizeValue(nsAStrin
 
         aValue = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(aValue);
       }
       break;
     case NS_FORM_INPUT_NUMBER:
       {
         nsresult ec;
         double val = PromiseFlatString(aValue).ToDouble(&ec);
-        if (NS_FAILED(ec) || !MOZ_DOUBLE_IS_FINITE(val)) {
+        if (NS_FAILED(ec) || !IsFinite(val)) {
           aValue.Truncate();
         }
       }
       break;
     case NS_FORM_INPUT_RANGE:
       {
         Decimal minimum = GetMinimum();
         Decimal maximum = GetMaximum();
--- a/content/html/content/src/HTMLInputElement.h
+++ b/content/html/content/src/HTMLInputElement.h
@@ -576,17 +576,17 @@ public:
 
   Nullable<Date> GetValueAsDate(ErrorResult& aRv);
 
   void SetValueAsDate(Nullable<Date>, ErrorResult& aRv);
 
   double ValueAsNumber() const
   {
     return DoesValueAsNumberApply() ? GetValueAsDecimal().toDouble()
-                                    : MOZ_DOUBLE_NaN();
+                                    : UnspecifiedNaN();
   }
 
   void SetValueAsNumber(double aValue, ErrorResult& aRv);
 
   uint32_t Width();
 
   void SetWidth(uint32_t aValue, ErrorResult& aRv)
   {
--- a/content/media/AudioEventTimeline.h
+++ b/content/media/AudioEventTimeline.h
@@ -125,17 +125,17 @@ struct AudioTimelineEvent {
   double mDuration;
 #ifdef DEBUG
   bool mTimeIsInTicks;
 #endif
 
 private:
   static bool IsValid(double value)
   {
-    return MOZ_DOUBLE_IS_FINITE(value);
+    return mozilla::IsFinite(value);
   }
 };
 
 template <>
 inline double AudioTimelineEvent::Time<double>() const
 {
   MOZ_ASSERT(!mTimeIsInTicks);
   return mTime;
--- a/content/media/MediaDecoder.cpp
+++ b/content/media/MediaDecoder.cpp
@@ -1214,19 +1214,19 @@ void MediaDecoder::DurationChanged()
     LOG(PR_LOG_DEBUG, ("%p duration changed to %lld", this, mDuration));
     mOwner->DispatchEvent(NS_LITERAL_STRING("durationchange"));
   }
 }
 
 void MediaDecoder::SetDuration(double aDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (MOZ_DOUBLE_IS_INFINITE(aDuration)) {
+  if (mozilla::IsInfinite(aDuration)) {
     SetInfinite(true);
-  } else if (MOZ_DOUBLE_IS_NaN(aDuration)) {
+  } else if (IsNaN(aDuration)) {
     mDuration = -1;
     SetInfinite(true);
   } else {
     mDuration = static_cast<int64_t>(NS_round(aDuration * static_cast<double>(USECS_PER_S)));
   }
 
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   if (mDecoderStateMachine) {
--- a/content/media/webaudio/WebAudioUtils.h
+++ b/content/media/webaudio/WebAudioUtils.h
@@ -85,17 +85,17 @@ struct WebAudioUtils {
    */
   static float ConvertDecibelToLinear(float aDecibel)
   {
     return std::pow(10.0f, 0.05f * aDecibel);
   }
 
   static void FixNaN(double& aDouble)
   {
-    if (MOZ_DOUBLE_IS_NaN(aDouble) || MOZ_DOUBLE_IS_INFINITE(aDouble)) {
+    if (IsNaN(aDouble) || IsInfinite(aDouble)) {
       aDouble = 0.0;
     }
   }
 
   static double DiscreteTimeConstantForSampleRate(double timeConstant, double sampleRate)
   {
     return 1.0 - std::exp(-1.0 / (sampleRate * timeConstant));
   }
--- a/content/media/webaudio/blink/DynamicsCompressorKernel.cpp
+++ b/content/media/webaudio/blink/DynamicsCompressorKernel.cpp
@@ -32,16 +32,18 @@
 #include <algorithm>
 
 #include "mozilla/FloatingPoint.h"
 #include "WebAudioUtils.h"
 
 using namespace std;
 
 using mozilla::dom::WebAudioUtils;
+using mozilla::IsInfinite;
+using mozilla::IsNaN;
 
 namespace WebCore {
 
 
 // Metering hits peaks instantly, but releases this fast (in seconds).
 const float meteringReleaseTimeConstant = 0.325f;
 
 const float uninitializedValue = -1;
@@ -280,19 +282,19 @@ void DynamicsCompressorKernel::process(f
 
     unsigned frameIndex = 0;
     for (int i = 0; i < nDivisions; ++i) {
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         // Calculate desired gain
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
         // Fix gremlins.
-        if (MOZ_DOUBLE_IS_NaN(m_detectorAverage))
+        if (IsNaN(m_detectorAverage))
             m_detectorAverage = 1;
-        if (MOZ_DOUBLE_IS_INFINITE(m_detectorAverage))
+        if (IsInfinite(m_detectorAverage))
             m_detectorAverage = 1;
 
         float desiredGain = m_detectorAverage;
 
         // Pre-warp so we get desiredGain after sin() warp below.
         float scaledDesiredGain = asinf(desiredGain) / (0.5f * M_PI);
 
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -308,19 +310,19 @@ void DynamicsCompressorKernel::process(f
         // compressionDiffDb is the difference between current compression level and the desired level.
         float compressionDiffDb = WebAudioUtils::ConvertLinearToDecibels(m_compressorGain / scaledDesiredGain, -1000.0f);
 
         if (isReleasing) {
             // Release mode - compressionDiffDb should be negative dB
             m_maxAttackCompressionDiffDb = -1;
 
             // Fix gremlins.
-            if (MOZ_DOUBLE_IS_NaN(compressionDiffDb))
+            if (IsNaN(compressionDiffDb))
                 compressionDiffDb = -1;
-            if (MOZ_DOUBLE_IS_INFINITE(compressionDiffDb))
+            if (IsInfinite(compressionDiffDb))
                 compressionDiffDb = -1;
 
             // Adaptive release - higher compression (lower compressionDiffDb)  releases faster.
 
             // Contain within range: -12 -> 0 then scale to go from 0 -> 3
             float x = compressionDiffDb;
             x = max(-12.0f, x);
             x = min(0.0f, x);
@@ -336,19 +338,19 @@ void DynamicsCompressorKernel::process(f
 #define kSpacingDb 5
             float dbPerFrame = kSpacingDb / releaseFrames;
 
             envelopeRate = WebAudioUtils::ConvertDecibelsToLinear(dbPerFrame);
         } else {
             // Attack mode - compressionDiffDb should be positive dB
 
             // Fix gremlins.
-            if (MOZ_DOUBLE_IS_NaN(compressionDiffDb))
+            if (IsNaN(compressionDiffDb))
                 compressionDiffDb = 1;
-            if (MOZ_DOUBLE_IS_INFINITE(compressionDiffDb))
+            if (IsInfinite(compressionDiffDb))
                 compressionDiffDb = 1;
 
             // As long as we're still in attack mode, use a rate based off
             // the largest compressionDiffDb we've encountered so far.
             if (m_maxAttackCompressionDiffDb == -1 || m_maxAttackCompressionDiffDb < compressionDiffDb)
                 m_maxAttackCompressionDiffDb = compressionDiffDb;
 
             float effAttenDiffDb = max(0.5f, m_maxAttackCompressionDiffDb);
@@ -404,19 +406,19 @@ void DynamicsCompressorKernel::process(f
 
                 bool isRelease = (attenuation > detectorAverage);
                 float rate = isRelease ? satReleaseRate : 1;
 
                 detectorAverage += (attenuation - detectorAverage) * rate;
                 detectorAverage = min(1.0f, detectorAverage);
 
                 // Fix gremlins.
-                if (MOZ_DOUBLE_IS_NaN(detectorAverage))
+                if (IsNaN(detectorAverage))
                     detectorAverage = 1;
-                if (MOZ_DOUBLE_IS_INFINITE(detectorAverage))
+                if (IsInfinite(detectorAverage))
                     detectorAverage = 1;
 
                 // Exponential approach to desired gain.
                 if (envelopeRate < 1) {
                     // Attack - reduce gain to desired.
                     compressorGain += (scaledDesiredGain - compressorGain) * envelopeRate;
                 } else {
                     // Release - exponentially increase gain to 1.0
--- a/content/xslt/src/base/txDouble.cpp
+++ b/content/xslt/src/base/txDouble.cpp
@@ -100,17 +100,17 @@ public:
         }
     }
 
     double
     getDouble()
     {
         if (mState == eIllegal || mBuffer.IsEmpty() ||
             (mBuffer.Length() == 1 && mBuffer[0] == '.')) {
-            return MOZ_DOUBLE_NaN();
+            return mozilla::UnspecifiedNaN();
         }
         return mSign*PR_strtod(mBuffer.get(), 0);
     }
 private:
     nsAutoCString mBuffer;
     enum {
         eWhitestart,
         eDecimal,
@@ -137,21 +137,21 @@ double txDouble::toDouble(const nsAStrin
  * The result into the destination String.
  * @return the given dest string
  */
 void txDouble::toString(double aValue, nsAString& aDest)
 {
 
     // check for special cases
 
-    if (MOZ_DOUBLE_IS_NaN(aValue)) {
+    if (mozilla::IsNaN(aValue)) {
         aDest.AppendLiteral("NaN");
         return;
     }
-    if (MOZ_DOUBLE_IS_INFINITE(aValue)) {
+    if (mozilla::IsInfinite(aValue)) {
         if (aValue < 0)
             aDest.Append(PRUnichar('-'));
         aDest.AppendLiteral("Infinity");
         return;
     }
 
     // Mantissa length is 17, so this is plenty
     const int buflen = 20;
--- a/content/xslt/src/xpath/txCoreFunctionCall.cpp
+++ b/content/xslt/src/xpath/txCoreFunctionCall.cpp
@@ -359,33 +359,33 @@ txCoreFunctionCall::evaluate(txIEvalCont
             rv = mParams[0]->evaluateToString(aContext, src);
             NS_ENSURE_SUCCESS(rv, rv);
 
             double start;
             rv = evaluateToNumber(mParams[1], aContext, &start);
             NS_ENSURE_SUCCESS(rv, rv);
 
             // check for NaN or +/-Inf
-            if (MOZ_DOUBLE_IS_NaN(start) ||
-                MOZ_DOUBLE_IS_INFINITE(start) ||
+            if (mozilla::IsNaN(start) ||
+                mozilla::IsInfinite(start) ||
                 start >= src.Length() + 0.5) {
                 aContext->recycler()->getEmptyStringResult(aResult);
 
                 return NS_OK;
             }
 
             start = floor(start + 0.5) - 1;
 
             double end;
             if (mParams.Length() == 3) {
                 rv = evaluateToNumber(mParams[2], aContext, &end);
                 NS_ENSURE_SUCCESS(rv, rv);
 
                 end += start;
-                if (MOZ_DOUBLE_IS_NaN(end) || end < 0) {
+                if (mozilla::IsNaN(end) || end < 0) {
                     aContext->recycler()->getEmptyStringResult(aResult);
 
                     return NS_OK;
                 }
                 
                 if (end > src.Length())
                     end = src.Length();
                 else
@@ -519,54 +519,49 @@ txCoreFunctionCall::evaluate(txIEvalCont
             return aContext->recycler()->getNumberResult(res, aResult);
         }
         case ROUND:
         {
             double dbl;
             rv = evaluateToNumber(mParams[0], aContext, &dbl);
             NS_ENSURE_SUCCESS(rv, rv);
 
-            if (!MOZ_DOUBLE_IS_NaN(dbl) && !MOZ_DOUBLE_IS_INFINITE(dbl)) {
-                if (MOZ_DOUBLE_IS_NEGATIVE(dbl) && dbl >= -0.5) {
+            if (mozilla::IsFinite(dbl)) {
+                if (mozilla::IsNegative(dbl) && dbl >= -0.5) {
                     dbl *= 0;
                 }
                 else {
                     dbl = floor(dbl + 0.5);
                 }
             }
 
             return aContext->recycler()->getNumberResult(dbl, aResult);
         }
         case FLOOR:
         {
             double dbl;
             rv = evaluateToNumber(mParams[0], aContext, &dbl);
             NS_ENSURE_SUCCESS(rv, rv);
 
-            if (!MOZ_DOUBLE_IS_NaN(dbl) &&
-                !MOZ_DOUBLE_IS_INFINITE(dbl) &&
-                !(dbl == 0 && MOZ_DOUBLE_IS_NEGATIVE(dbl))) {
+            if (mozilla::IsFinite(dbl) && !mozilla::IsNegativeZero(dbl))
                 dbl = floor(dbl);
-            }
 
             return aContext->recycler()->getNumberResult(dbl, aResult);
         }
         case CEILING:
         {
             double dbl;
             rv = evaluateToNumber(mParams[0], aContext, &dbl);
             NS_ENSURE_SUCCESS(rv, rv);
 
-            if (!MOZ_DOUBLE_IS_NaN(dbl) && !MOZ_DOUBLE_IS_INFINITE(dbl)) {
-                if (MOZ_DOUBLE_IS_NEGATIVE(dbl) && dbl > -1) {
+            if (mozilla::IsFinite(dbl)) {
+                if (mozilla::IsNegative(dbl) && dbl > -1)
                     dbl *= 0;
-                }
-                else {
+                else
                     dbl = ceil(dbl);
-                }
             }
 
             return aContext->recycler()->getNumberResult(dbl, aResult);
         }
         case SUM:
         {
             nsRefPtr<txNodeSet> nodes;
             nsresult rv = evaluateToNodeSet(mParams[0], aContext,
--- a/content/xslt/src/xpath/txNumberExpr.cpp
+++ b/content/xslt/src/xpath/txNumberExpr.cpp
@@ -34,39 +34,39 @@ txNumberExpr::evaluate(txIEvalContext* a
         case SUBTRACT:
             result = leftDbl - rightDbl;
             break;
 
         case DIVIDE:
             if (rightDbl == 0) {
 #if defined(XP_WIN)
                 /* XXX MSVC miscompiles such that (NaN == 0) */
-                if (MOZ_DOUBLE_IS_NaN(rightDbl))
-                    result = MOZ_DOUBLE_NaN();
+                if (mozilla::IsNaN(rightDbl))
+                    result = mozilla::UnspecifiedNaN();
                 else
 #endif
-                if (leftDbl == 0 || MOZ_DOUBLE_IS_NaN(leftDbl))
-                    result = MOZ_DOUBLE_NaN();
-                else if (MOZ_DOUBLE_IS_NEGATIVE(leftDbl) ^ MOZ_DOUBLE_IS_NEGATIVE(rightDbl))
-                    result = MOZ_DOUBLE_NEGATIVE_INFINITY();
+                if (leftDbl == 0 || mozilla::IsNaN(leftDbl))
+                    result = mozilla::UnspecifiedNaN();
+                else if (mozilla::IsNegative(leftDbl) != mozilla::IsNegative(rightDbl))
+                    result = mozilla::NegativeInfinity();
                 else
-                    result = MOZ_DOUBLE_POSITIVE_INFINITY();
+                    result = mozilla::PositiveInfinity();
             }
             else
                 result = leftDbl / rightDbl;
             break;
 
         case MODULUS:
             if (rightDbl == 0) {
-                result = MOZ_DOUBLE_NaN();
+                result = mozilla::UnspecifiedNaN();
             }
             else {
 #if defined(XP_WIN)
                 /* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
-                if (!MOZ_DOUBLE_IS_INFINITE(leftDbl) && MOZ_DOUBLE_IS_INFINITE(rightDbl))
+                if (!mozilla::IsInfinite(leftDbl) && mozilla::IsInfinite(rightDbl))
                     result = leftDbl;
                 else
 #endif
                 result = fmod(leftDbl, rightDbl);
             }
             break;
 
         case MULTIPLY:
--- a/content/xslt/src/xpath/txNumberResult.cpp
+++ b/content/xslt/src/xpath/txNumberResult.cpp
@@ -44,16 +44,16 @@ NumberResult::stringValuePointer()
 {
     return nullptr;
 }
 
 bool NumberResult::booleanValue() {
   // OG+
   // As per the XPath spec, the boolean value of a number is true if and only if
   // it is neither positive 0 nor negative 0 nor NaN
-  return (bool)(value != 0.0 && !MOZ_DOUBLE_IS_NaN(value));
+  return (bool)(value != 0.0 && !mozilla::IsNaN(value));
   // OG-
 } //-- booleanValue
 
 double NumberResult::numberValue() {
     return this->value;
 } //-- numberValue
 
--- a/content/xslt/src/xpath/txUnionNodeTest.cpp
+++ b/content/xslt/src/xpath/txUnionNodeTest.cpp
@@ -23,17 +23,17 @@ txUnionNodeTest::matches(const txXPathNo
 
     return false;
 }
 
 double
 txUnionNodeTest::getDefaultPriority()
 {
     NS_ERROR("Don't call getDefaultPriority on txUnionPattern");
-    return MOZ_DOUBLE_NaN();
+    return mozilla::UnspecifiedNaN();
 }
 
 bool
 txUnionNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext)
 {
     uint32_t i, len = mNodeTests.Length();
     for (i = 0; i < len; ++i) {
         if (mNodeTests[i]->isSensitiveTo(aContext)) {
--- a/content/xslt/src/xslt/txEXSLTFunctions.cpp
+++ b/content/xslt/src/xslt/txEXSLTFunctions.cpp
@@ -563,30 +563,30 @@ txEXSLTFunctionCall::evaluate(txIEvalCon
         {
             nsRefPtr<txNodeSet> nodes;
             rv = evaluateToNodeSet(mParams[0], aContext,
                                    getter_AddRefs(nodes));
             NS_ENSURE_SUCCESS(rv, rv);
 
             if (nodes->isEmpty()) {
                 return aContext->recycler()->
-                    getNumberResult(MOZ_DOUBLE_NaN(), aResult);
+                    getNumberResult(UnspecifiedNaN(), aResult);
             }
 
             bool findMax = mType == MAX;
 
-            double res = findMax ? MOZ_DOUBLE_NEGATIVE_INFINITY() :
-                                   MOZ_DOUBLE_POSITIVE_INFINITY();
+            double res = findMax ? mozilla::NegativeInfinity() :
+                                   mozilla::PositiveInfinity();
             int32_t i, len = nodes->size();
             for (i = 0; i < len; ++i) {
                 nsAutoString str;
                 txXPathNodeUtils::appendNodeValue(nodes->get(i), str);
                 double val = txDouble::toDouble(str);
-                if (MOZ_DOUBLE_IS_NaN(val)) {
-                    res = MOZ_DOUBLE_NaN();
+                if (mozilla::IsNaN(val)) {
+                    res = UnspecifiedNaN();
                     break;
                 }
 
                 if (findMax ? (val > res) : (val < res)) {
                     res = val;
                 }
             }
 
@@ -606,25 +606,25 @@ txEXSLTFunctionCall::evaluate(txIEvalCon
                 return NS_OK;
             }
 
             nsRefPtr<txNodeSet> resultSet;
             rv = aContext->recycler()->getNodeSet(getter_AddRefs(resultSet));
             NS_ENSURE_SUCCESS(rv, rv);
 
             bool findMax = mType == HIGHEST;
-            double res = findMax ? MOZ_DOUBLE_NEGATIVE_INFINITY() :
-                                   MOZ_DOUBLE_POSITIVE_INFINITY();
+            double res = findMax ? mozilla::NegativeInfinity() :
+                                   mozilla::PositiveInfinity();
             int32_t i, len = nodes->size();
             for (i = 0; i < len; ++i) {
                 nsAutoString str;
                 const txXPathNode& node = nodes->get(i);
                 txXPathNodeUtils::appendNodeValue(node, str);
                 double val = txDouble::toDouble(str);
-                if (MOZ_DOUBLE_IS_NaN(val)) {
+                if (mozilla::IsNaN(val)) {
                     resultSet->clear();
                     break;
                 }
                 if (findMax ? (val > res) : (val < res)) {
                     resultSet->clear();
                     res = val;
                 }
 
--- a/content/xslt/src/xslt/txFormatNumberFunctionCall.cpp
+++ b/content/xslt/src/xslt/txFormatNumberFunctionCall.cpp
@@ -76,26 +76,26 @@ txFormatNumberFunctionCall::evaluate(txI
         err.AppendLiteral(" for: ");
         toString(err);
 #endif
         aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
         return NS_ERROR_XPATH_INVALID_ARG;
     }
 
     // Special cases
-    if (MOZ_DOUBLE_IS_NaN(value)) {
+    if (mozilla::IsNaN(value)) {
         return aContext->recycler()->getStringResult(format->mNaN, aResult);
     }
 
-    if (value == MOZ_DOUBLE_POSITIVE_INFINITY()) {
+    if (value == mozilla::PositiveInfinity()) {
         return aContext->recycler()->getStringResult(format->mInfinity,
                                                      aResult);
     }
 
-    if (value == MOZ_DOUBLE_NEGATIVE_INFINITY()) {
+    if (value == mozilla::NegativeInfinity()) {
         nsAutoString res;
         res.Append(format->mMinusSign);
         res.Append(format->mInfinity);
         return aContext->recycler()->getStringResult(res, aResult);
     }
     
     // Value is a normal finite number
     nsAutoString prefix;
@@ -107,17 +107,17 @@ txFormatNumberFunctionCall::evaluate(txI
     int groupSize=-1;
 
     uint32_t pos = 0;
     uint32_t formatLen = formatStr.Length();
     bool inQuote;
 
     // Get right subexpression
     inQuote = false;
-    if (MOZ_DOUBLE_IS_NEGATIVE(value)) {
+    if (mozilla::IsNegative(value)) {
         while (pos < formatLen &&
                (inQuote ||
                 formatStr.CharAt(pos) != format->mPatternSeparator)) {
             if (formatStr.CharAt(pos) == FORMAT_QUOTE)
                 inQuote = !inQuote;
             pos++;
         }
 
--- a/content/xslt/src/xslt/txStylesheet.cpp
+++ b/content/xslt/src/xslt/txStylesheet.cpp
@@ -406,19 +406,19 @@ txStylesheet::addTemplate(txTemplateItem
         unionPattern = simple;
         simple = unionPattern->getSubPatternAt(0);
         unionPattern->setSubPatternAt(0, nullptr);
     }
 
     uint32_t unionPos = 1; // only used when unionPattern is set
     while (simple) {
         double priority = aTemplate->mPrio;
-        if (MOZ_DOUBLE_IS_NaN(priority)) {
+        if (mozilla::IsNaN(priority)) {
             priority = simple->getDefaultPriority();
-            NS_ASSERTION(!MOZ_DOUBLE_IS_NaN(priority),
+            NS_ASSERTION(!mozilla::IsNaN(priority),
                          "simple pattern without default priority");
         }
 
         uint32_t i, len = templates->Length();
         for (i = 0; i < len; ++i) {
             if (priority > (*templates)[i].mPriority) {
                 break;
             }
--- a/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
+++ b/content/xslt/src/xslt/txStylesheetCompileHandlers.cpp
@@ -266,26 +266,26 @@ getPatternAttr(txStylesheetAttr* aAttrib
 static nsresult
 getNumberAttr(txStylesheetAttr* aAttributes,
               int32_t aAttrCount,
               nsIAtom* aName,
               bool aRequired,
               txStylesheetCompilerState& aState,
               double& aNumber)
 {
-    aNumber = MOZ_DOUBLE_NaN();
+    aNumber = UnspecifiedNaN();
     txStylesheetAttr* attr = nullptr;
     nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None,
                                aName, aRequired, &attr);
     if (!attr) {
         return rv;
     }
 
     aNumber = txDouble::toDouble(attr->mValue);
-    if (MOZ_DOUBLE_IS_NaN(aNumber) && (aRequired || !aState.fcp())) {
+    if (mozilla::IsNaN(aNumber) && (aRequired || !aState.fcp())) {
         // XXX ErrorReport: number parse failure
         return NS_ERROR_XSLT_PARSE_FAILURE;
     }
 
     return NS_OK;
 }
 
 static nsresult
@@ -515,17 +515,17 @@ txFnStartLREStylesheet(int32_t aNamespac
                        txStylesheetCompilerState& aState)
 {
     txStylesheetAttr* attr;
     nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_XSLT,
                                nsGkAtoms::version, true, &attr);
     NS_ENSURE_SUCCESS(rv, rv);
 
     txExpandedName nullExpr;
-    double prio = MOZ_DOUBLE_NaN();
+    double prio = UnspecifiedNaN();
 
     nsAutoPtr<txPattern> match(new txRootPattern());
     NS_ENSURE_TRUE(match, NS_ERROR_OUT_OF_MEMORY);
 
     nsAutoPtr<txTemplateItem> templ(new txTemplateItem(match, nullExpr,
                                                        nullExpr, prio));
     NS_ENSURE_TRUE(templ, NS_ERROR_OUT_OF_MEMORY);
 
@@ -1108,17 +1108,17 @@ txFnStartTemplate(int32_t aNamespaceID,
                       aState, name);
     NS_ENSURE_SUCCESS(rv, rv);
 
     txExpandedName mode;
     rv = getQNameAttr(aAttributes, aAttrCount, nsGkAtoms::mode, false,
                       aState, mode);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    double prio = MOZ_DOUBLE_NaN();
+    double prio = UnspecifiedNaN();
     rv = getNumberAttr(aAttributes, aAttrCount, nsGkAtoms::priority,
                        false, aState, prio);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoPtr<txPattern> match;
     rv = getPatternAttr(aAttributes, aAttrCount, nsGkAtoms::match,
                         name.isNull(), aState, match);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/content/xslt/src/xslt/txXPathResultComparator.cpp
+++ b/content/xslt/src/xslt/txXPathResultComparator.cpp
@@ -209,19 +209,19 @@ txResultNumberComparator::createSortable
     return NS_OK;
 }
 
 int txResultNumberComparator::compareValues(txObject* aVal1, txObject* aVal2)
 {
     double dval1 = ((NumberValue*)aVal1)->mVal;
     double dval2 = ((NumberValue*)aVal2)->mVal;
 
-    if (MOZ_DOUBLE_IS_NaN(dval1))
-        return MOZ_DOUBLE_IS_NaN(dval2) ? 0 : -mAscending;
+    if (mozilla::IsNaN(dval1))
+        return mozilla::IsNaN(dval2) ? 0 : -mAscending;
 
-    if (MOZ_DOUBLE_IS_NaN(dval2))
+    if (mozilla::IsNaN(dval2))
         return mAscending;
 
     if (dval1 == dval2)
         return 0;
     
     return (dval1 < dval2) ? -mAscending : mAscending;
 }
--- a/content/xslt/src/xslt/txXSLTNumber.cpp
+++ b/content/xslt/src/xslt/txXSLTNumber.cpp
@@ -86,17 +86,17 @@ txXSLTNumber::getValueList(Expr* aValueE
     // If the value attribute exists then use that
     if (aValueExpr) {
         nsRefPtr<txAExprResult> result;
         rv = aValueExpr->evaluate(aContext, getter_AddRefs(result));
         NS_ENSURE_SUCCESS(rv, rv);
 
         double value = result->numberValue();
 
-        if (MOZ_DOUBLE_IS_INFINITE(value) || MOZ_DOUBLE_IS_NaN(value) ||
+        if (mozilla::IsInfinite(value) || mozilla::IsNaN(value) ||
             value < 0.5) {
             txDouble::toString(value, aValueString);
             return NS_OK;
         }
         
         aValues.add(NS_INT32_TO_PTR((int32_t)floor(value + 0.5)));
         return NS_OK;
     }
--- a/content/xslt/src/xslt/txXSLTPatterns.cpp
+++ b/content/xslt/src/xslt/txXSLTPatterns.cpp
@@ -18,17 +18,17 @@
 /*
  * Returns the default priority of this Pattern.
  * UnionPatterns don't like this.
  * This should be called on the simple patterns.
  */
 double txUnionPattern::getDefaultPriority()
 {
     NS_ERROR("Don't call getDefaultPriority on txUnionPattern");
-    return MOZ_DOUBLE_NaN();
+    return mozilla::UnspecifiedNaN();
 }
 
 /*
  * Determines whether this Pattern matches the given node within
  * the given context
  * This should be called on the simple patterns for xsl:template,
  * but is fine for xsl:key and xsl:number
  */
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -1729,24 +1729,24 @@ ReportLenientThisUnwrappingFailure(JSCon
   if (window && window->GetDoc()) {
     window->GetDoc()->WarnOnceAbout(nsIDocument::eLenientThis);
   }
   return true;
 }
 
 // Date implementation methods
 Date::Date() :
-  mMsecSinceEpoch(MOZ_DOUBLE_NaN())
+  mMsecSinceEpoch(UnspecifiedNaN())
 {
 }
 
 bool
 Date::IsUndefined() const
 {
-  return MOZ_DOUBLE_IS_NaN(mMsecSinceEpoch);
+  return IsNaN(mMsecSinceEpoch);
 }
 
 bool
 Date::SetTimeStamp(JSContext* cx, JSObject* objArg)
 {
   JS::Rooted<JSObject*> obj(cx, objArg);
   MOZ_ASSERT(JS_ObjectIsDate(cx, obj));
 
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2251,21 +2251,21 @@ numericSuffixes = {
     IDLType.Tags.unrestricted_double: 'D',
     IDLType.Tags.double: 'D'
 }
 
 def numericValue(t, v):
     if (t == IDLType.Tags.unrestricted_double or
         t == IDLType.Tags.unrestricted_float):
         if v == float("inf"):
-            return "MOZ_DOUBLE_POSITIVE_INFINITY()"
+            return "mozilla::PositiveInfinity()"
         if v == float("-inf"):
-            return "MOZ_DOUBLE_NEGATIVE_INFINITY()"
+            return "mozilla::NegativeInfinity()"
         if math.isnan(v):
-            return "MOZ_DOUBLE_NaN()"
+            return "mozilla::UnspecifiedNaN()"
     return "%s%s" % (v, numericSuffixes[t])
 
 class CastableObjectUnwrapper():
     """
     A class for unwrapping an object named by the "source" argument
     based on the passed-in descriptor and storing it in a variable
     called by the name in the "target" argument.
 
@@ -3388,18 +3388,18 @@ for (uint32_t i = 0; i < length; ++i) {
         declType = CGGeneric(typeName)
 
     if type.isFloat() and not type.isUnrestricted():
         if lenientFloatCode is not None:
             nonFiniteCode = CGIndenter(CGGeneric(lenientFloatCode)).define()
         else:
             nonFiniteCode = ("  ThrowErrorMessage(cx, MSG_NOT_FINITE);\n"
                              "%s" % exceptionCodeIndented.define())
-        template += (" else if (!MOZ_DOUBLE_IS_FINITE(%s)) {\n"
-                     "  // Note: MOZ_DOUBLE_IS_FINITE will do the right thing\n"
+        template += (" else if (!mozilla::IsFinite(%s)) {\n"
+                     "  // Note: mozilla::IsFinite will do the right thing\n"
                      "  //       when passed a non-finite float too.\n"
                      "%s\n"
                      "}" % (readLoc, nonFiniteCode))
 
     if (defaultValue is not None and
         # We already handled IDLNullValue, so just deal with the other ones
         not isinstance(defaultValue, IDLNullValue)):
         tag = defaultValue.type.tag()
--- a/dom/bindings/PrimitiveConversions.h
+++ b/dom/bindings/PrimitiveConversions.h
@@ -218,17 +218,17 @@ struct PrimitiveConversionTraits_ToCheck
 
 template<typename T>
 inline bool
 PrimitiveConversionTraits_EnforceRange(JSContext* cx, const double& d, T* retval)
 {
   MOZ_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
                     "This can only be applied to integers!");
 
-  if (!MOZ_DOUBLE_IS_FINITE(d)) {
+  if (!mozilla::IsFinite(d)) {
     return ThrowErrorMessage(cx, MSG_ENFORCE_RANGE_NON_FINITE, TypeName<T>::value());
   }
 
   bool neg = (d < 0);
   double rounded = floor(neg ? -d : d);
   rounded = neg ? -rounded : rounded;
   if (rounded < PrimitiveConversionTraits_Limits<T>::min() ||
       rounded > PrimitiveConversionTraits_Limits<T>::max()) {
@@ -246,30 +246,30 @@ struct PrimitiveConversionTraits<T, eEnf
 
 template<typename T>
 inline bool
 PrimitiveConversionTraits_Clamp(JSContext* cx, const double& d, T* retval)
 {
   MOZ_STATIC_ASSERT(std::numeric_limits<T>::is_integer,
                     "This can only be applied to integers!");
 
-  if (MOZ_DOUBLE_IS_NaN(d)) {
+  if (mozilla::IsNaN(d)) {
     *retval = 0;
     return true;
   }
   if (d >= PrimitiveConversionTraits_Limits<T>::max()) {
     *retval = PrimitiveConversionTraits_Limits<T>::max();
     return true;
   }
   if (d <= PrimitiveConversionTraits_Limits<T>::min()) {
     *retval = PrimitiveConversionTraits_Limits<T>::min();
     return true;
   }
 
-  MOZ_ASSERT(MOZ_DOUBLE_IS_FINITE(d));
+  MOZ_ASSERT(mozilla::IsFinite(d));
 
   // Banker's rounding (round ties towards even).
   // We move away from 0 by 0.5f and then truncate.  That gets us the right
   // answer for any starting value except plus or minus N.5.  With a starting
   // value of that form, we now have plus or minus N+1.  If N is odd, this is
   // the correct result.  If N is even, plus or minus N is the correct result.
   double toTruncate = (d < 0) ? d - 0.5 : d + 0.5;
 
--- a/dom/indexedDB/Key.cpp
+++ b/dom/indexedDB/Key.cpp
@@ -120,17 +120,17 @@ Key::EncodeJSValInternal(JSContext* aCx,
 
   if (JSVAL_IS_INT(aVal)) {
     EncodeNumber((double)JSVAL_TO_INT(aVal), eFloat + aTypeOffset);
     return NS_OK;
   }
 
   if (JSVAL_IS_DOUBLE(aVal)) {
     double d = JSVAL_TO_DOUBLE(aVal);
-    if (MOZ_DOUBLE_IS_NaN(d)) {
+    if (mozilla::IsNaN(d)) {
       return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
     }
     EncodeNumber(d, eFloat + aTypeOffset);
     return NS_OK;
   }
 
   if (!JSVAL_IS_PRIMITIVE(aVal)) {
     JS::Rooted<JSObject*> obj(aCx, JSVAL_TO_OBJECT(aVal));
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -4767,18 +4767,18 @@ gfxFontStyle::gfxFontStyle(uint8_t aStyl
                            const nsString& aLanguageOverride):
     language(aLanguage),
     size(aSize), sizeAdjust(aSizeAdjust),
     languageOverride(ParseFontLanguageOverride(aLanguageOverride)),
     weight(aWeight), stretch(aStretch),
     systemFont(aSystemFont), printerFont(aPrinterFont),
     style(aStyle)
 {
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(size));
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(sizeAdjust));
+    MOZ_ASSERT(!mozilla::IsNaN(size));
+    MOZ_ASSERT(!mozilla::IsNaN(sizeAdjust));
 
     if (weight > 900)
         weight = 900;
     if (weight < 100)
         weight = 100;
 
     if (size >= FONT_MAX_SIZE) {
         size = FONT_MAX_SIZE;
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -919,23 +919,23 @@ class Value
         } else {
             setInt32((int32_t)ui);
             return true;
         }
     }
 
     bool setNumber(double d) {
         int32_t i;
-        if (MOZ_DOUBLE_IS_INT32(d, &i)) {
+        if (mozilla::DoubleIsInt32(d, &i)) {
             setInt32(i);
             return true;
-        } else {
-            setDouble(d);
-            return false;
         }
+
+        setDouble(d);
+        return false;
     }
 
     void setObjectOrNull(JSObject *arg) {
         if (arg)
             setObject(*arg);
         else
             setNull();
     }
--- a/js/src/builtin/Intl.cpp
+++ b/js/src/builtin/Intl.cpp
@@ -35,16 +35,19 @@
 #include "unicode/ustring.h"
 #endif
 #include "unicode/utypes.h"
 
 #include "jsobjinlines.h"
 
 using namespace js;
 
+using mozilla::IsFinite;
+using mozilla::IsNegativeZero;
+
 #if ENABLE_INTL_API
 using icu::Locale;
 using icu::NumberingSystem;
 #endif
 
 
 /*
  * Pervasive note: ICU functions taking a UErrorCode in/out parameter always
@@ -1424,17 +1427,17 @@ NewUNumberFormat(JSContext *cx, HandleOb
 
     return toClose.forget();
 }
 
 static bool
 intl_FormatNumber(JSContext *cx, UNumberFormat *nf, double x, MutableHandleValue result)
 {
     // FormatNumber doesn't consider -0.0 to be negative.
-    if (MOZ_DOUBLE_IS_NEGATIVE_ZERO(x))
+    if (IsNegativeZero(x))
         x = 0.0;
 
     StringBuffer chars(cx);
     if (!chars.resize(INITIAL_STRING_BUFFER_SIZE))
         return false;
     UErrorCode status = U_ZERO_ERROR;
     int size = unum_formatDouble(nf, x, chars.begin(), INITIAL_STRING_BUFFER_SIZE, NULL, &status);
     if (status == U_BUFFER_OVERFLOW_ERROR) {
@@ -1903,17 +1906,17 @@ NewUDateFormat(JSContext *cx, HandleObje
     // An error here means the calendar is not Gregorian, so we don't care.
 
     return df;
 }
 
 static bool
 intl_FormatDateTime(JSContext *cx, UDateFormat *df, double x, MutableHandleValue result)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(x)) {
+    if (!IsFinite(x)) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DATE_NOT_FINITE);
         return false;
     }
 
     StringBuffer chars(cx);
     if (!chars.resize(INITIAL_STRING_BUFFER_SIZE))
         return false;
     UErrorCode status = U_ZERO_ERROR;
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -14,16 +14,19 @@
 #include "js/Utility.h"
 #include "vm/GlobalObject.h"
 #include "vm/Stack.h"
 
 #include "jsobjinlines.h"
 
 using namespace js;
 
+using mozilla::DoubleIsInt32;
+using mozilla::IsNaN;
+
 
 /*** OrderedHashTable ****************************************************************************/
 
 /*
  * Define two collection templates, js::OrderedHashMap and js::OrderedHashSet.
  * They are like js::HashMap and js::HashSet except that:
  *
  *   - Iterating over an Ordered hash table visits the entries in the order in
@@ -785,20 +788,20 @@ HashableValue::setValue(JSContext *cx, c
         // Atomize so that hash() and operator==() are fast and infallible.
         JSString *str = AtomizeString<CanGC>(cx, v.toString(), DoNotInternAtom);
         if (!str)
             return false;
         value = StringValue(str);
     } else if (v.isDouble()) {
         double d = v.toDouble();
         int32_t i;
-        if (MOZ_DOUBLE_IS_INT32(d, &i)) {
+        if (DoubleIsInt32(d, &i)) {
             // Normalize int32_t-valued doubles to int32_t for faster hashing and testing.
             value = Int32Value(i);
-        } else if (MOZ_DOUBLE_IS_NaN(d)) {
+        } else if (IsNaN(d)) {
             // NaNs with different bits must hash and test identically.
             value = DoubleValue(js_NaN);
         } else {
             value = v;
         }
     } else {
         value = v;
     }
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -1899,17 +1899,17 @@ template<class IntegerType>
 static bool
 jsvalToIntegerExplicit(jsval val, IntegerType* result)
 {
   JS_STATIC_ASSERT(numeric_limits<IntegerType>::is_exact);
 
   if (JSVAL_IS_DOUBLE(val)) {
     // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
     double d = JSVAL_TO_DOUBLE(val);
-    *result = MOZ_DOUBLE_IS_FINITE(d) ? IntegerType(d) : 0;
+    *result = mozilla::IsFinite(d) ? IntegerType(d) : 0;
     return true;
   }
   if (!JSVAL_IS_PRIMITIVE(val)) {
     // Convert Int64 and UInt64 values by C-style cast.
     JSObject* obj = JSVAL_TO_OBJECT(val);
     if (Int64::IsInt64(obj)) {
       int64_t i = Int64Base::GetInt(obj);
       *result = IntegerType(i);
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -47,16 +47,17 @@
 #include "frontend/SharedContext-inl.h"
 #include "vm/Shape-inl.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::frontend;
 
 using mozilla::DebugOnly;
+using mozilla::DoubleIsInt32;
 using mozilla::PodCopy;
 
 static bool
 SetSrcNoteOffset(JSContext *cx, BytecodeEmitter *bce, unsigned index, unsigned which, ptrdiff_t offset);
 
 struct frontend::StmtInfoBCE : public StmtInfoBase
 {
     StmtInfoBCE     *down;          /* info for enclosing statement */
@@ -2110,17 +2111,17 @@ EmitElemIncDec(JSContext *cx, ParseNode 
 static bool
 EmitNumberOp(JSContext *cx, double dval, BytecodeEmitter *bce)
 {
     int32_t ival;
     uint32_t u;
     ptrdiff_t off;
     jsbytecode *pc;
 
-    if (MOZ_DOUBLE_IS_INT32(dval, &ival)) {
+    if (DoubleIsInt32(dval, &ival)) {
         if (ival == 0)
             return Emit1(cx, bce, JSOP_ZERO) >= 0;
         if (ival == 1)
             return Emit1(cx, bce, JSOP_ONE) >= 0;
         if ((int)(int8_t)ival == ival)
             return Emit2(cx, bce, JSOP_INT8, (jsbytecode)(int8_t)ival) >= 0;
 
         u = (uint32_t)ival;
@@ -2267,17 +2268,17 @@ EmitSwitch(JSContext *cx, BytecodeEmitte
             pn4 = pn3->pn_left;
 
             if (pn4->getKind() != PNK_NUMBER) {
                 switchOp = JSOP_CONDSWITCH;
                 continue;
             }
 
             int32_t i;
-            if (!MOZ_DOUBLE_IS_INT32(pn4->pn_dval, &i)) {
+            if (!DoubleIsInt32(pn4->pn_dval, &i)) {
                 switchOp = JSOP_CONDSWITCH;
                 continue;
             }
 
             if ((unsigned)(i + (int)JS_BIT(15)) >= (unsigned)JS_BIT(16)) {
                 switchOp = JSOP_CONDSWITCH;
                 continue;
             }
--- a/js/src/frontend/FoldConstants.cpp
+++ b/js/src/frontend/FoldConstants.cpp
@@ -16,16 +16,19 @@
 #include "jsatominlines.h"
 
 #include "frontend/Parser-inl.h"
 #include "vm/String-inl.h"
 
 using namespace js;
 using namespace js::frontend;
 
+using mozilla::IsNaN;
+using mozilla::IsNegative;
+
 static ParseNode *
 ContainsVarOrConst(ParseNode *pn)
 {
     if (!pn)
         return NULL;
     if (pn->isKind(PNK_VAR) || pn->isKind(PNK_CONST))
         return pn;
     switch (pn->getArity()) {
@@ -142,23 +145,23 @@ FoldBinaryNumeric(JSContext *cx, JSOp op
       case JSOP_MUL:
         d *= d2;
         break;
 
       case JSOP_DIV:
         if (d2 == 0) {
 #if defined(XP_WIN)
             /* XXX MSVC miscompiles such that (NaN == 0) */
-            if (MOZ_DOUBLE_IS_NaN(d2))
+            if (IsNaN(d2))
                 d = js_NaN;
             else
 #endif
-            if (d == 0 || MOZ_DOUBLE_IS_NaN(d))
+            if (d == 0 || IsNaN(d))
                 d = js_NaN;
-            else if (MOZ_DOUBLE_IS_NEGATIVE(d) != MOZ_DOUBLE_IS_NEGATIVE(d2))
+            else if (IsNegative(d) != IsNegative(d2))
                 d = js_NegativeInfinity;
             else
                 d = js_PositiveInfinity;
         } else {
             d /= d2;
         }
         break;
 
@@ -197,17 +200,17 @@ ReplaceNode(ParseNode **pnp, ParseNode *
 
 enum Truthiness { Truthy, Falsy, Unknown };
 
 static Truthiness
 Boolish(ParseNode *pn)
 {
     switch (pn->getOp()) {
       case JSOP_DOUBLE:
-        return (pn->pn_dval != 0 && !MOZ_DOUBLE_IS_NaN(pn->pn_dval)) ? Truthy : Falsy;
+        return (pn->pn_dval != 0 && !IsNaN(pn->pn_dval)) ? Truthy : Falsy;
 
       case JSOP_STRING:
         return (pn->pn_atom->length() > 0) ? Truthy : Falsy;
 
 #if JS_HAS_GENERATOR_EXPRS
       case JSOP_CALL:
       {
         /*
@@ -391,17 +394,17 @@ FoldConstants<FullParseHandler>(JSContex
         if (ContainsVarOrConst(pn2) || ContainsVarOrConst(pn3))
             break;
         /* FALL THROUGH */
 
       case PNK_CONDITIONAL:
         /* Reduce 'if (C) T; else E' into T for true C, E for false. */
         switch (pn1->getKind()) {
           case PNK_NUMBER:
-            if (pn1->pn_dval == 0 || MOZ_DOUBLE_IS_NaN(pn1->pn_dval))
+            if (pn1->pn_dval == 0 || IsNaN(pn1->pn_dval))
                 pn2 = pn3;
             break;
           case PNK_STRING:
             if (pn1->pn_atom->length() == 0)
                 pn2 = pn3;
             break;
           case PNK_TRUE:
             break;
@@ -673,17 +676,17 @@ FoldConstants<FullParseHandler>(JSContex
               case JSOP_NEG:
                 d = -d;
                 break;
 
               case JSOP_POS:
                 break;
 
               case JSOP_NOT:
-                if (d == 0 || MOZ_DOUBLE_IS_NaN(d)) {
+                if (d == 0 || IsNaN(d)) {
                     pn->setKind(PNK_TRUE);
                     pn->setOp(JSOP_TRUE);
                 } else {
                     pn->setKind(PNK_FALSE);
                     pn->setOp(JSOP_FALSE);
                 }
                 pn->setArity(PN_NULLARY);
                 /* FALL THROUGH */
--- a/js/src/frontend/ParseNode.cpp
+++ b/js/src/frontend/ParseNode.cpp
@@ -12,16 +12,18 @@
 
 #include "frontend/ParseMaps-inl.h"
 #include "frontend/ParseNode-inl.h"
 #include "frontend/Parser-inl.h"
 
 using namespace js;
 using namespace js::frontend;
 
+using mozilla::IsFinite;
+
 /*
  * Asserts to verify assumptions behind pn_ macros.
  */
 #define pn_offsetof(m)  offsetof(ParseNode, m)
 
 JS_STATIC_ASSERT(pn_offsetof(pn_link) == pn_offsetof(dn_uses));
 
 #undef pn_offsetof
@@ -630,17 +632,17 @@ NullaryNode::dump()
     switch (getKind()) {
       case PNK_TRUE:  fprintf(stderr, "#true");  break;
       case PNK_FALSE: fprintf(stderr, "#false"); break;
       case PNK_NULL:  fprintf(stderr, "#null");  break;
 
       case PNK_NUMBER: {
         ToCStringBuf cbuf;
         const char *cstr = NumberToCString(NULL, &cbuf, pn_dval);
-        if (!MOZ_DOUBLE_IS_FINITE(pn_dval))
+        if (!IsFinite(pn_dval))
             fputc('#', stderr);
         if (cstr)
             fprintf(stderr, "%s", cstr);
         else
             fprintf(stderr, "%g", pn_dval);
         break;
       }
 
--- a/js/src/ion/AsmJSLink.cpp
+++ b/js/src/ion/AsmJSLink.cpp
@@ -146,18 +146,18 @@ ValidateGlobalConstant(JSContext *cx, As
     RootedValue v(cx);
     if (!GetProperty(cx, globalVal, field, &v))
         return false;
 
     if (!v.isNumber())
         return LinkFail(cx, "global constant value needs to be a number");
 
     // NaN != NaN
-    if (MOZ_DOUBLE_IS_NaN(global.constantValue())) {
-        if (!MOZ_DOUBLE_IS_NaN(v.toNumber()))
+    if (IsNaN(global.constantValue())) {
+        if (!IsNaN(v.toNumber()))
             return LinkFail(cx, "global constant value needs to be NaN");
     } else {
         if (v.toNumber() != global.constantValue())
             return LinkFail(cx, "global constant value mismatch");
     }
 
     return true;
 }
--- a/js/src/ion/RangeAnalysis.cpp
+++ b/js/src/ion/RangeAnalysis.cpp
@@ -17,16 +17,20 @@
 #include "MIRGraph.h"
 #include "RangeAnalysis.h"
 #include "IonSpewer.h"
 
 using namespace js;
 using namespace js::ion;
 
 using mozilla::Abs;
+using mozilla::ExponentComponent;
+using mozilla::IsInfinite;
+using mozilla::IsNaN;
+using mozilla::IsNegative;
 
 // This algorithm is based on the paper "Eliminating Range Checks Using
 // Static Single Assignment Form" by Gough and Klaren.
 //
 // We associate a range object with each SSA name, and the ranges are consulted
 // in order to determine whether overflow is possible for arithmetic
 // computations.
 //
@@ -574,52 +578,52 @@ MConstant::computeRange()
 
     if (type() != MIRType_Double)
         return;
 
     double d = value().toDouble();
     int exp = Range::MaxDoubleExponent;
 
     // NaN is estimated as a Double which covers everything.
-    if (MOZ_DOUBLE_IS_NaN(d)) {
+    if (IsNaN(d)) {
         setRange(new Range(RANGE_INF_MIN, RANGE_INF_MAX, true, exp));
         return;
     }
 
     // Infinity is used to set both lower and upper to the range boundaries.
-    if (MOZ_DOUBLE_IS_INFINITE(d)) {
-        if (MOZ_DOUBLE_IS_NEGATIVE(d))
+    if (IsInfinite(d)) {
+        if (IsNegative(d))
             setRange(new Range(RANGE_INF_MIN, RANGE_INF_MIN, false, exp));
         else
             setRange(new Range(RANGE_INF_MAX, RANGE_INF_MAX, false, exp));
         return;
     }
 
     // Extract the exponent, to approximate it with the range analysis.
-    exp = MOZ_DOUBLE_EXPONENT(d);
+    exp = ExponentComponent(d);
     if (exp < 0) {
         // This double only has a decimal part.
-        if (MOZ_DOUBLE_IS_NEGATIVE(d))
+        if (IsNegative(d))
             setRange(new Range(-1, 0, true, 0));
         else
             setRange(new Range(0, 1, true, 0));
     } else if (exp < Range::MaxTruncatableExponent) {
         // Extract the integral part.
         int64_t integral = ToInt64(d);
         // Extract the decimal part.
         double rest = d - (double) integral;
         // Estimate the smallest integral boundaries.
         //   Safe double comparisons, because there is no precision loss.
         int64_t l = integral - ((rest < 0) ? 1 : 0);
         int64_t h = integral + ((rest > 0) ? 1 : 0);
         setRange(new Range(l, h, (rest != 0), exp));
     } else {
         // This double has a precision loss. This also mean that it cannot
         // encode any decimals.
-        if (MOZ_DOUBLE_IS_NEGATIVE(d))
+        if (IsNegative(d))
             setRange(new Range(RANGE_INF_MIN, RANGE_INF_MIN, false, exp));
         else
             setRange(new Range(RANGE_INF_MAX, RANGE_INF_MAX, false, exp));
     }
 }
 
 void
 MCharCodeAt::computeRange()
--- a/js/src/ion/RangeAnalysis.h
+++ b/js/src/ion/RangeAnalysis.h
@@ -97,20 +97,20 @@ class Range : public TempObject {
   public:
     // Int32 are signed, so the value needs 31 bits except for INT_MIN value
     // which needs 32 bits.
     static const uint16_t MaxInt32Exponent = 31;
 
     // Maximal exponenent under which we have no precission loss on double
     // operations. Double has 52 bits of mantissa, so 2^52+1 cannot be
     // represented without loss.
-    static const uint16_t MaxTruncatableExponent = MOZ_DOUBLE_EXPONENT_SHIFT;
+    static const uint16_t MaxTruncatableExponent = mozilla::DoubleExponentShift;
 
     // 11 bits of signed exponent, so the max is encoded on 10 bits.
-    static const uint16_t MaxDoubleExponent = MOZ_DOUBLE_EXPONENT_BIAS;
+    static const uint16_t MaxDoubleExponent = mozilla::DoubleExponentBias;
 
   private:
     // Absolute ranges.
     //
     // We represent ranges where the endpoints can be in the set:
     // {-infty} U [INT_MIN, INT_MAX] U {infty}.  A bound of +/-
     // infty means that the value may have overflowed in that
     // direction. When computing the range of an integer
--- a/js/src/ion/x86/CodeGenerator-x86.cpp
+++ b/js/src/ion/x86/CodeGenerator-x86.cpp
@@ -16,16 +16,18 @@
 
 #include "jsscriptinlines.h"
 #include "ion/ExecutionModeInlines.h"
 
 using namespace js;
 using namespace js::ion;
 
 using mozilla::DebugOnly;
+using mozilla::DoubleExponentBias;
+using mozilla::DoubleExponentShift;
 
 CodeGeneratorX86::CodeGeneratorX86(MIRGenerator *gen, LIRGraph *graph, MacroAssembler *masm)
   : CodeGeneratorX86Shared(gen, graph, masm)
 {
 }
 
 static const uint32_t FrameSizes[] = { 128, 256, 512, 1024 };
 
@@ -710,18 +712,18 @@ CodeGeneratorX86::visitOutOfLineTruncate
     Label fail;
 
     if (Assembler::HasSSE3()) {
         // Push double.
         masm.subl(Imm32(sizeof(double)), esp);
         masm.movsd(input, Operand(esp, 0));
 
         static const uint32_t EXPONENT_MASK = 0x7ff00000;
-        static const uint32_t EXPONENT_SHIFT = MOZ_DOUBLE_EXPONENT_SHIFT - 32;
-        static const uint32_t TOO_BIG_EXPONENT = (MOZ_DOUBLE_EXPONENT_BIAS + 63) << EXPONENT_SHIFT;
+        static const uint32_t EXPONENT_SHIFT = DoubleExponentShift - 32;
+        static const uint32_t TOO_BIG_EXPONENT = (DoubleExponentBias + 63) << EXPONENT_SHIFT;
 
         // Check exponent to avoid fp exceptions.
         Label failPopDouble;
         masm.movl(Operand(esp, 4), output);
         masm.and32(Imm32(EXPONENT_MASK), output);
         masm.branch32(Assembler::GreaterThanOrEqual, output, Imm32(TOO_BIG_EXPONENT), &failPopDouble);
 
         // Load double, perform 64-bit truncation.
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -497,17 +497,17 @@ JS_ValueToNumber(JSContext *cx, jsval va
 {
     RootedValue value(cx, valueArg);
     return JS::ToNumber(cx, value, dp);
 }
 
 JS_PUBLIC_API(JSBool)
 JS_DoubleIsInt32(double d, int32_t *ip)
 {
-    return MOZ_DOUBLE_IS_INT32(d, ip);
+    return mozilla::DoubleIsInt32(d, ip);
 }
 
 JS_PUBLIC_API(int32_t)
 JS_DoubleToInt32(double d)
 {
     return ToInt32(d);
 }
 
@@ -561,17 +561,17 @@ JS_ValueToInt32(JSContext *cx, jsval vAr
 
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else if (!ToNumberSlow(cx, v, &d)) {
         return false;
     }
 
-    if (MOZ_DOUBLE_IS_NaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
+    if (mozilla::IsNaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
         js_ReportValueError(cx, JSMSG_CANT_CONVERT,
                             JSDVG_SEARCH_STACK, v, NullPtr());
         return false;
     }
 
     *ip = (int32_t) floor(d + 0.5);  /* Round to nearest */
     return true;
 }
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1159,17 +1159,17 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL
 extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE;
 extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID;
 
 static JS_ALWAYS_INLINE jsval
 JS_NumberValue(double d)
 {
     int32_t i;
     d = JS_CANONICALIZE_NAN(d);
-    if (MOZ_DOUBLE_IS_INT32(d, &i))
+    if (mozilla::DoubleIsInt32(d, &i))
         return INT_TO_JSVAL(i);
     return DOUBLE_TO_JSVAL(d);
 }
 
 /************************************************************************/
 
 /*
  * A jsid is an identifier for a property or method of an object which is
@@ -1538,17 +1538,17 @@ ToBoolean(const Value &v)
     if (v.isBoolean())
         return v.toBoolean();
     if (v.isInt32())
         return v.toInt32() != 0;
     if (v.isNullOrUndefined())
         return false;
     if (v.isDouble()) {
         double d = v.toDouble();
-        return !MOZ_DOUBLE_IS_NaN(d) && d != 0;
+        return !mozilla::IsNaN(d) && d != 0;
     }
 
     /* The slow path handles strings and objects. */
     return js::ToBooleanSlow(v);
 }
 
 } /* namespace JS */
 
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -42,16 +42,17 @@
 #include "vm/ObjectImpl-inl.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
 using mozilla::ArrayLength;
 using mozilla::DebugOnly;
+using mozilla::IsNaN;
 using mozilla::PointerRangeSize;
 
 JSBool
 js::GetLengthProperty(JSContext *cx, HandleObject obj, uint32_t *lengthp)
 {
     if (obj->isArray()) {
         *lengthp = obj->getArrayLength();
         return true;
@@ -1466,17 +1467,17 @@ SortComparatorFunction::operator()(const
     if (!ToNumber(cx, ag.rval(), &cmp))
         return false;
 
     /*
      * XXX eport some kind of error here if cmp is NaN? ECMA talks about
      * 'consistent compare functions' that don't return NaN, but is silent
      * about what the result should be. So we currently ignore it.
      */
-    *lessOrEqualp = (MOZ_DOUBLE_IS_NaN(cmp) || cmp <= 0);
+    *lessOrEqualp = (IsNaN(cmp) || cmp <= 0);
     return true;
 }
 
 struct NumericElement
 {
     double dv;
     size_t elementIndex;
 };
--- a/js/src/jsclone.cpp
+++ b/js/src/jsclone.cpp
@@ -36,16 +36,18 @@
 #include "jstypedarray.h"
 
 #include "jstypedarrayinlines.h"
 
 #include "vm/BooleanObject-inl.h"
 #include "vm/RegExpObject-inl.h"
 
 using namespace js;
+
+using mozilla::IsNaN;
 using mozilla::LittleEndian;
 using mozilla::NativeEndian;
 
 enum StructuredDataType {
     /* Structured data types provided by the engine */
     SCTAG_FLOAT_MAX = 0xFFF00000,
     SCTAG_NULL = 0xFFFF0000,
     SCTAG_UNDEFINED,
@@ -1053,17 +1055,17 @@ JSStructuredCloneReader::startRead(Value
             return false;
         break;
       }
 
       case SCTAG_DATE_OBJECT: {
         double d;
         if (!in.readDouble(&d) || !checkDouble(d))
             return false;
-        if (!MOZ_DOUBLE_IS_NaN(d) && d != TimeClip(d)) {
+        if (!IsNaN(d) && d != TimeClip(d)) {
             JS_ReportErrorNumber(context(), js_GetErrorMessage, NULL, JSMSG_SC_BAD_SERIALIZED_DATA,
                                  "date");
             return false;
         }
         JSObject *obj = js_NewDateObjectMsec(context(), d);
         if (!obj)
             return false;
         vp->setObject(*obj);
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -48,16 +48,18 @@
 #include "jsobjinlines.h"
 
 #include "js/Date.h"
 
 using namespace js;
 using namespace js::types;
 
 using mozilla::ArrayLength;
+using mozilla::IsFinite;
+using mozilla::IsNaN;
 
 /*
  * The JS 'Date' object is patterned after the Java 'Date' object.
  * Here is a script:
  *
  *    today = new Date();
  *
  *    print(today.toLocaleString());
@@ -123,17 +125,17 @@ IsLeapYear(double year)
 {
     JS_ASSERT(ToInteger(year) == year);
     return fmod(year, 4) == 0 && (fmod(year, 100) != 0 || fmod(year, 400) == 0);
 }
 
 inline double
 DaysInYear(double year)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(year))
+    if (!IsFinite(year))
         return js_NaN;
     return IsLeapYear(year) ? 366 : 365;
 }
 
 inline double
 DayFromYear(double y)
 {
     return 365 * (y - 1970) +
@@ -146,17 +148,17 @@ inline double
 TimeFromYear(double y)
 {
     return DayFromYear(y) * msPerDay;
 }
 
 static double
 YearFromTime(double t)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(t))
+    if (!IsFinite(t))
         return js_NaN;
 
     JS_ASSERT(ToInteger(t) == t);
 
     double y = floor(t / (msPerDay * 365.2425)) + 1970;
     double t2 = TimeFromYear(y);
 
     /*
@@ -178,24 +180,24 @@ DaysInFebruary(double year)
 {
     return IsLeapYear(year) ? 29 : 28;
 }
 
 /* ES5 15.9.1.4. */
 inline double
 DayWithinYear(double t, double year)
 {
-    JS_ASSERT_IF(MOZ_DOUBLE_IS_FINITE(t), YearFromTime(t) == year);
+    JS_ASSERT_IF(IsFinite(t), YearFromTime(t) == year);
     return Day(t) - DayFromYear(year);
 }
 
 static double
 MonthFromTime(double t)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(t))
+    if (!IsFinite(t))
         return js_NaN;
 
     double year = YearFromTime(t);
     double d = DayWithinYear(t, year);
 
     int step;
     if (d < (step = 31))
         return 0;
@@ -221,17 +223,17 @@ MonthFromTime(double t)
         return 10;
     return 11;
 }
 
 /* ES5 15.9.1.5. */
 static double
 DateFromTime(double t)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(t))
+    if (!IsFinite(t))
         return js_NaN;
 
     double year = YearFromTime(t);
     double d = DayWithinYear(t, year);
 
     int next;
     if (d <= (next = 30))
         return d + 1;
@@ -304,17 +306,17 @@ template<typename T>
 inline int
 DayFromMonth(T month, bool isLeapYear) MOZ_DELETE;
 
 /* ES5 15.9.1.12 (out of order to accommodate DaylightSavingTA). */
 static double
 MakeDay(double year, double month, double date)
 {
     /* Step 1. */
-    if (!MOZ_DOUBLE_IS_FINITE(year) || !MOZ_DOUBLE_IS_FINITE(month) || !MOZ_DOUBLE_IS_FINITE(date))
+    if (!IsFinite(year) || !IsFinite(month) || !IsFinite(date))
         return js_NaN;
 
     /* Steps 2-4. */
     double y = ToInteger(year);
     double m = ToInteger(month);
     double dt = ToInteger(date);
 
     /* Step 5. */
@@ -334,17 +336,17 @@ MakeDay(double year, double month, doubl
     return yearday + monthday + dt - 1;
 }
 
 /* ES5 15.9.1.13 (out of order to accommodate DaylightSavingTA). */
 inline double
 MakeDate(double day, double time)
 {
     /* Step 1. */
-    if (!MOZ_DOUBLE_IS_FINITE(day) || !MOZ_DOUBLE_IS_FINITE(time))
+    if (!IsFinite(day) || !IsFinite(time))
         return js_NaN;
 
     /* Step 2. */
     return day * msPerDay + time;
 }
 
 JS_PUBLIC_API(double)
 JS::MakeDate(double year, unsigned month, unsigned day)
@@ -400,17 +402,17 @@ EquivalentYearForDST(int year)
 
     return yearStartingWith[IsLeapYear(year)][day];
 }
 
 /* ES5 15.9.1.8. */
 static double
 DaylightSavingTA(double t, DateTimeInfo *dtInfo)
 {
-    if (!MOZ_DOUBLE_IS_FINITE(t))
+    if (!IsFinite(t))
         return js_NaN;
 
     /*
      * If earlier than 1970 or after 2038, potentially beyond the ken of
      * many OSes, map it to an equivalent year before asking.
      */
     if (t < 0.0 || t > 2145916800000.0) {
         int year = EquivalentYearForDST(int(YearFromTime(t)));
@@ -481,20 +483,20 @@ msFromTime(double t)
     return result;
 }
 
 /* ES5 15.9.1.11. */
 static double
 MakeTime(double hour, double min, double sec, double ms)
 {
     /* Step 1. */
-    if (!MOZ_DOUBLE_IS_FINITE(hour) ||
-        !MOZ_DOUBLE_IS_FINITE(min) ||
-        !MOZ_DOUBLE_IS_FINITE(sec) ||
-        !MOZ_DOUBLE_IS_FINITE(ms))
+    if (!IsFinite(hour) ||
+        !IsFinite(min) ||
+        !IsFinite(sec) ||
+        !IsFinite(ms))
     {
         return js_NaN;
     }
 
     /* Step 2. */
     double h = ToInteger(hour);
 
     /* Step 3. */
@@ -614,17 +616,17 @@ date_msecFromArgs(JSContext *cx, CallArg
     double msec_time;
 
     for (loop = 0; loop < MAXARGS; loop++) {
         if (loop < args.length()) {
             double d;
             if (!ToNumber(cx, args[loop], &d))
                 return JS_FALSE;
             /* return NaN if any arg is not finite */
-            if (!MOZ_DOUBLE_IS_FINITE(d)) {
+            if (!IsFinite(d)) {
                 *rval = js_NaN;
                 return JS_TRUE;
             }
             array[loop] = ToInteger(d);
         } else {
             if (loop == 2) {
                 array[loop] = 1; /* Default the date argument to 1. */
             } else {
@@ -1276,17 +1278,17 @@ FillLocalTimeSlots(DateTimeInfo *dtInfo,
         return;
     }
 
     /* Remember timezone used to generate the local cache. */
     obj->setSlot(JSObject::JSSLOT_DATE_TZA, DoubleValue(dtInfo->localTZA()));
 
     double utcTime = obj->getDateUTCTime().toNumber();
 
-    if (!MOZ_DOUBLE_IS_FINITE(utcTime)) {
+    if (!IsFinite(utcTime)) {
         for (size_t ind = JSObject::JSSLOT_DATE_COMPONENTS_START;
              ind < JSObject::DATE_CLASS_RESERVED_SLOTS;
              ind++) {
             obj->setSlot(ind, DoubleValue(utcTime));
         }
         return;
     }
 
@@ -1478,17 +1480,17 @@ date_getFullYear(JSContext *cx, unsigned
 }
 
 JS_ALWAYS_INLINE bool
 date_getUTCFullYear_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = YearFromTime(result);
 
     args.rval().setNumber(result);
     return true;
 }
 
 static JSBool
 date_getUTCFullYear(JSContext *cx, unsigned argc, Value *vp)
@@ -1553,17 +1555,17 @@ date_getDate(JSContext *cx, unsigned arg
 }
 
 JS_ALWAYS_INLINE bool
 date_getUTCDate_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = DateFromTime(result);
 
     args.rval().setNumber(result);
     return true;
 }
 
 static JSBool
 date_getUTCDate(JSContext *cx, unsigned argc, Value *vp)
@@ -1592,17 +1594,17 @@ date_getDay(JSContext *cx, unsigned argc
 }
 
 JS_ALWAYS_INLINE bool
 date_getUTCDay_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = WeekDay(result);
 
     args.rval().setNumber(result);
     return true;
 }
 
 static JSBool
 date_getUTCDay(JSContext *cx, unsigned argc, Value *vp)
@@ -1631,17 +1633,17 @@ date_getHours(JSContext *cx, unsigned ar
 }
 
 JS_ALWAYS_INLINE bool
 date_getUTCHours_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = HourFromTime(result);
 
     args.rval().setNumber(result);
     return JS_TRUE;
 }
 
 static JSBool
 date_getUTCHours(JSContext *cx, unsigned argc, Value *vp)
@@ -1670,17 +1672,17 @@ date_getMinutes(JSContext *cx, unsigned 
 }
 
 JS_ALWAYS_INLINE bool
 date_getUTCMinutes_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = MinFromTime(result);
 
     args.rval().setNumber(result);
     return true;
 }
 
 static JSBool
 date_getUTCMinutes(JSContext *cx, unsigned argc, Value *vp)
@@ -1713,17 +1715,17 @@ date_getUTCSeconds(JSContext *cx, unsign
 /* Date.getMilliseconds is mapped to getUTCMilliseconds */
 
 JS_ALWAYS_INLINE bool
 date_getUTCMilliseconds_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double result = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_FINITE(result))
+    if (IsFinite(result))
         result = msFromTime(result);
 
     args.rval().setNumber(result);
     return true;
 }
 
 static JSBool
 date_getUTCMilliseconds(JSContext *cx, unsigned argc, Value *vp)
@@ -2307,26 +2309,26 @@ date_setUTCMonth(JSContext *cx, unsigned
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<IsDate, date_setUTCMonth_impl>(cx, args);
 }
 
 static double
 ThisLocalTimeOrZero(HandleObject date, DateTimeInfo *dtInfo)
 {
     double t = date->getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_NaN(t))
+    if (IsNaN(t))
         return +0;
     return LocalTime(t, dtInfo);
 }
 
 static double
 ThisUTCTimeOrZero(HandleObject date)
 {
     double t = date->getDateUTCTime().toNumber();
-    return MOZ_DOUBLE_IS_NaN(t) ? +0 : t;
+    return IsNaN(t) ? +0 : t;
 }
 
 /* ES5 15.9.5.40. */
 JS_ALWAYS_INLINE bool
 date_setFullYear_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
@@ -2424,17 +2426,17 @@ date_setYear_impl(JSContext *cx, CallArg
     double t = ThisLocalTimeOrZero(thisObj, &cx->runtime->dateTimeInfo);
 
     /* Step 2. */
     double y;
     if (!ToNumber(cx, args.length() > 0 ? args[0] : UndefinedValue(), &y))
         return false;
 
     /* Step 3. */
-    if (MOZ_DOUBLE_IS_NaN(y)) {
+    if (IsNaN(y)) {
         SetUTCTime(thisObj, js_NaN, args.rval().address());
         return true;
     }
 
     /* Step 4. */
     double yint = ToInteger(y);
     if (0 <= yint && yint <= 99)
         yint += 1900;
@@ -2503,17 +2505,17 @@ print_iso_string(char* buf, size_t size,
 JS_ALWAYS_INLINE bool
 date_toGMTString_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double utctime = args.thisv().toObject().getDateUTCTime().toNumber();
 
     char buf[100];
-    if (!MOZ_DOUBLE_IS_FINITE(utctime))
+    if (!IsFinite(utctime))
         JS_snprintf(buf, sizeof buf, js_NaN_date_str);
     else
         print_gmt_string(buf, sizeof buf, utctime);
 
     JSString *str = JS_NewStringCopyZ(cx, buf);
     if (!str)
         return false;
     args.rval().setString(str);
@@ -2529,17 +2531,17 @@ date_toGMTString(JSContext *cx, unsigned
 }
 
 JS_ALWAYS_INLINE bool
 date_toISOString_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     double utctime = args.thisv().toObject().getDateUTCTime().toNumber();
-    if (!MOZ_DOUBLE_IS_FINITE(utctime)) {
+    if (!IsFinite(utctime)) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INVALID_DATE);
         return false;
     }
 
     char buf[100];
     print_iso_string(buf, sizeof buf, utctime);
 
     JSString *str = JS_NewStringCopyZ(cx, buf);
@@ -2569,17 +2571,17 @@ date_toJSON(JSContext *cx, unsigned argc
         return false;
 
     /* Step 2. */
     RootedValue tv(cx, ObjectValue(*obj));
     if (!ToPrimitive(cx, JSTYPE_NUMBER, &tv))
         return false;
 
     /* Step 3. */
-    if (tv.isDouble() && !MOZ_DOUBLE_IS_FINITE(tv.toDouble())) {
+    if (tv.isDouble() && !IsFinite(tv.toDouble())) {
         args.rval().setNull();
         return true;
     }
 
     /* Step 4. */
     RootedValue toISO(cx);
     if (!JSObject::getProperty(cx, obj, obj, cx->names().toISOString, &toISO))
         return false;
@@ -2636,17 +2638,17 @@ static JSBool
 date_format(JSContext *cx, double date, formatspec format, MutableHandleValue rval)
 {
     char buf[100];
     char tzbuf[100];
     JSBool usetz;
     size_t i, tzlen;
     PRMJTime split;
 
-    if (!MOZ_DOUBLE_IS_FINITE(date)) {
+    if (!IsFinite(date)) {
         JS_snprintf(buf, sizeof buf, js_NaN_date_str);
     } else {
         JS_ASSERT(TimeClip(date) == date);
 
         double local = LocalTime(date, &cx->runtime->dateTimeInfo);
 
         /* offset from GMT in minutes.  The offset includes daylight savings,
            if it applies. */
@@ -2747,17 +2749,17 @@ date_format(JSContext *cx, double date, 
 }
 
 static bool
 ToLocaleFormatHelper(JSContext *cx, HandleObject obj, const char *format, MutableHandleValue rval)
 {
     double utctime = obj->getDateUTCTime().toNumber();
 
     char buf[100];
-    if (!MOZ_DOUBLE_IS_FINITE(utctime)) {
+    if (!IsFinite(utctime)) {
         JS_snprintf(buf, sizeof buf, js_NaN_date_str);
     } else {
         int result_len;
         double local = LocalTime(utctime, &cx->runtime->dateTimeInfo);
         PRMJTime split;
         new_explode(local, &split, &cx->runtime->dateTimeInfo);
 
         /* Let PRMJTime format it. */
@@ -3115,17 +3117,17 @@ js_Date(JSContext *cx, unsigned argc, Va
                 return false;
             d = TimeClip(d);
         }
     } else {
         double msec_time;
         if (!date_msecFromArgs(cx, args, &msec_time))
             return false;
 
-        if (MOZ_DOUBLE_IS_FINITE(msec_time)) {
+        if (IsFinite(msec_time)) {
             msec_time = UTC(msec_time, &cx->runtime->dateTimeInfo);
             msec_time = TimeClip(msec_time);
         }
         d = msec_time;
     }
 
     JSObject *obj = js_NewDateObjectMsec(cx, d);
     if (!obj)
@@ -3198,83 +3200,83 @@ js_NewDateObject(JSContext *cx, int year
     JS_ASSERT(mon < 12);
     double msec_time = date_msecFromDate(year, mon, mday, hour, min, sec, 0);
     return js_NewDateObjectMsec(cx, UTC(msec_time, &cx->runtime->dateTimeInfo));
 }
 
 JS_FRIEND_API(JSBool)
 js_DateIsValid(JSObject *obj)
 {
-    return obj->isDate() && !MOZ_DOUBLE_IS_NaN(obj->getDateUTCTime().toNumber());
+    return obj->isDate() && !IsNaN(obj->getDateUTCTime().toNumber());
 }
 
 JS_FRIEND_API(int)
 js_DateGetYear(JSContext *cx, JSObject *obj)
 {
     /* Preserve legacy API behavior of returning 0 for invalid dates. */
     JS_ASSERT(obj);
     double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
-    if (MOZ_DOUBLE_IS_NaN(localtime))
+    if (IsNaN(localtime))
         return 0;
 
     return (int) YearFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetMonth(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj);
     double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
-    if (MOZ_DOUBLE_IS_NaN(localtime))
+    if (IsNaN(localtime))
         return 0;
 
     return (int) MonthFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetDate(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj);
     double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
-    if (MOZ_DOUBLE_IS_NaN(localtime))
+    if (IsNaN(localtime))
         return 0;
 
     return (int) DateFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetHours(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj);
     double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
-    if (MOZ_DOUBLE_IS_NaN(localtime))
+    if (IsNaN(localtime))
         return 0;
 
     return (int) HourFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetMinutes(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj);
     double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
-    if (MOZ_DOUBLE_IS_NaN(localtime))
+    if (IsNaN(localtime))
         return 0;
 
     return (int) MinFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetSeconds(JSObject *obj)
 {
     if (!obj->isDate())
         return 0;
 
     double utctime = obj->getDateUTCTime().toNumber();
-    if (MOZ_DOUBLE_IS_NaN(utctime))
+    if (IsNaN(utctime))
         return 0;
     return (int) SecFromTime(utctime);
 }
 
 JS_FRIEND_API(double)
 js_DateGetMsecSinceEpoch(JSObject *obj)
 {
     return obj->isDate() ? obj->getDateUTCTime().toNumber() : 0;
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -722,23 +722,23 @@ js::StrictlyEqual(JSContext *cx, const V
 
     *equal = false;
     return true;
 }
 
 static inline bool
 IsNegativeZero(const Value &v)
 {
-    return v.isDouble() && MOZ_DOUBLE_IS_NEGATIVE_ZERO(v.toDouble());
+    return v.isDouble() && mozilla::IsNegativeZero(v.toDouble());
 }
 
 static inline bool
 IsNaN(const Value &v)
 {
-    return v.isDouble() && MOZ_DOUBLE_IS_NaN(v.toDouble());
+    return v.isDouble() && mozilla::IsNaN(v.toDouble());
 }
 
 bool
 js::SameValue(JSContext *cx, const Value &v1, const Value &v2, bool *same)
 {
     if (IsNegativeZero(v1)) {
         *same = IsNegativeZero(v2);
         return true;
@@ -2628,17 +2628,17 @@ BEGIN_CASE(JSOP_TABLESWITCH)
      * opcode is emitted only for dense int-domain switches.)
      */
     const Value &rref = *--regs.sp;
     int32_t i;
     if (rref.isInt32()) {
         i = rref.toInt32();
     } else {
         double d;
-        /* Don't use MOZ_DOUBLE_IS_INT32; treat -0 (double) as 0. */
+        /* Don't use mozilla::DoubleIsInt32; treat -0 (double) as 0. */
         if (!rref.isDouble() || (d = rref.toDouble()) != (i = int32_t(rref.toDouble())))
             DO_NEXT_OP(len);
     }
 
     pc2 += JUMP_OFFSET_LEN;
     int32_t low = GET_JUMP_OFFSET(pc2);
     pc2 += JUMP_OFFSET_LEN;
     int32_t high = GET_JUMP_OFFSET(pc2);
--- a/js/src/jslibmath.h
+++ b/js/src/jslibmath.h
@@ -35,38 +35,38 @@ extern "C" double js_myfmod(double x, do
 static inline double
 js_fmod(double d, double d2)
 {
 #ifdef XP_WIN
     /*
      * Workaround MS fmod bug where 42 % (1/0) => NaN, not 42.
      * Workaround MS fmod bug where -0 % -N => 0, not -0.
      */
-    if ((MOZ_DOUBLE_IS_FINITE(d) && MOZ_DOUBLE_IS_INFINITE(d2)) ||
-        (d == 0 && MOZ_DOUBLE_IS_FINITE(d2))) {
+    if ((mozilla::IsFinite(d) && mozilla::IsInfinite(d2)) ||
+        (d == 0 && mozilla::IsFinite(d2))) {
         return d;
     }
 #endif
     return fmod(d, d2);
 }
 
 namespace js {
 
 inline double
 NumberDiv(double a, double b)
 {
     if (b == 0) {
-        if (a == 0 || MOZ_DOUBLE_IS_NaN(a)
+        if (a == 0 || mozilla::IsNaN(a)
 #ifdef XP_WIN
-            || MOZ_DOUBLE_IS_NaN(b) /* XXX MSVC miscompiles such that (NaN == 0) */
+            || mozilla::IsNaN(b) /* XXX MSVC miscompiles such that (NaN == 0) */
 #endif
         )
             return js_NaN;
 
-        if (MOZ_DOUBLE_IS_NEGATIVE(a) != MOZ_DOUBLE_IS_NEGATIVE(b))
+        if (mozilla::IsNegative(a) != mozilla::IsNegative(b))
             return js_NegativeInfinity;
         return js_PositiveInfinity;
     }
 
     return a / b;
 }
 
 inline double
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -24,16 +24,26 @@
 #include "jslibmath.h"
 #include "jscompartment.h"
 
 #include "jsobjinlines.h"
 
 using namespace js;
 
 using mozilla::Abs;
+using mozilla::DoubleIsInt32;
+using mozilla::ExponentComponent;
+using mozilla::IsFinite;
+using mozilla::IsInfinite;
+using mozilla::IsNaN;
+using mozilla::IsNegative;
+using mozilla::IsNegativeZero;
+using mozilla::PositiveInfinity;
+using mozilla::NegativeInfinity;
+using mozilla::SpecificNaN;
 
 #ifndef M_E
 #define M_E             2.7182818284590452354
 #endif
 #ifndef M_LOG2E
 #define M_LOG2E         1.4426950408889634074
 #endif
 #ifndef M_LOG10E
@@ -63,18 +73,18 @@ static JSConstDoubleSpec math_constants[
     {M_SQRT1_2, "SQRT1_2",      0, {0,0,0}},
     {0,0,0,{0,0,0}}
 };
 
 MathCache::MathCache() {
     memset(table, 0, sizeof(table));
 
     /* See comments in lookup(). */
-    JS_ASSERT(MOZ_DOUBLE_IS_NEGATIVE_ZERO(-0.0));
-    JS_ASSERT(!MOZ_DOUBLE_IS_NEGATIVE_ZERO(+0.0));
+    JS_ASSERT(IsNegativeZero(-0.0));
+    JS_ASSERT(!IsNegativeZero(+0.0));
     JS_ASSERT(hash(-0.0) != hash(+0.0));
 }
 
 size_t
 MathCache::sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf)
 {
     return mallocSizeOf(this);
 }
@@ -196,17 +206,17 @@ js::ecmaAtan2(double x, double y)
 #if defined(_MSC_VER)
     /*
      * MSVC's atan2 does not yield the result demanded by ECMA when both x
      * and y are infinite.
      * - The result is a multiple of pi/4.
      * - The sign of x determines the sign of the result.
      * - The sign of y determines the multiplicator, 1 or 3.
      */
-    if (MOZ_DOUBLE_IS_INFINITE(x) && MOZ_DOUBLE_IS_INFINITE(y)) {
+    if (IsInfinite(x) && IsInfinite(y)) {
         double z = js_copysign(M_PI / 4, x);
         if (y < 0)
             z *= 3;
         return z;
     }
 #endif
 
 #if defined(SOLARIS) && defined(__GNUC__)
@@ -286,17 +296,17 @@ js::math_cos(JSContext *cx, unsigned arg
     vp->setDouble(z);
     return JS_TRUE;
 }
 
 double
 js::math_exp_impl(MathCache *cache, double x)
 {
 #ifdef _WIN32
-    if (!MOZ_DOUBLE_IS_NaN(x)) {
+    if (!IsNaN(x)) {
         if (x == js_PositiveInfinity)
             return js_PositiveInfinity;
         if (x == js_NegativeInfinity)
             return 0.0;
     }
 #endif
     return cache->lookup(exp, x);
 }
@@ -390,40 +400,40 @@ js::math_log(JSContext *cx, unsigned arg
 }
 
 JSBool
 js_math_max(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     double x;
-    double maxval = MOZ_DOUBLE_NEGATIVE_INFINITY();
+    double maxval = NegativeInfinity();
     for (unsigned i = 0; i < args.length(); i++) {
         if (!ToNumber(cx, args[i], &x))
             return false;
         // Math.max(num, NaN) => NaN, Math.max(-0, +0) => +0
-        if (x > maxval || MOZ_DOUBLE_IS_NaN(x) || (x == maxval && MOZ_DOUBLE_IS_NEGATIVE(maxval)))
+        if (x > maxval || IsNaN(x) || (x == maxval && IsNegative(maxval)))
             maxval = x;
     }
     args.rval().setNumber(maxval);
     return true;
 }
 
 JSBool
 js_math_min(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     double x;
-    double minval = MOZ_DOUBLE_POSITIVE_INFINITY();
+    double minval = PositiveInfinity();
     for (unsigned i = 0; i < args.length(); i++) {
         if (!ToNumber(cx, args[i], &x))
             return false;
         // Math.min(num, NaN) => NaN, Math.min(-0, +0) => -0
-        if (x < minval || MOZ_DOUBLE_IS_NaN(x) || (x == minval && MOZ_DOUBLE_IS_NEGATIVE_ZERO(x)))
+        if (x < minval || IsNaN(x) || (x == minval && IsNegativeZero(x)))
             minval = x;
     }
     args.rval().setNumber(minval);
     return true;
 }
 
 // Disable PGO for Math.pow() and related functions (see bug 791214).
 #if defined(_MSC_VER)
@@ -441,17 +451,17 @@ js::powi(double x, int y)
         if (n == 0) {
             if (y < 0) {
                 // Unfortunately, we have to be careful when p has reached
                 // infinity in the computation, because sometimes the higher
                 // internal precision in the pow() implementation would have
                 // given us a finite p. This happens very rarely.
 
                 double result = 1.0 / p;
-                return (result == 0 && MOZ_DOUBLE_IS_INFINITE(p))
+                return (result == 0 && IsInfinite(p))
                        ? pow(x, static_cast<double>(y))  // Avoid pow(double, int).
                        : result;
             }
 
             return p;
         }
         m *= m;
     }
@@ -473,17 +483,17 @@ js::ecmaPow(double x, double y)
      */
     if (int32_t(y) == y)
         return powi(x, int32_t(y));
 
     /*
      * Because C99 and ECMA specify different behavior for pow(),
      * we need to wrap the libm call to make it ECMA compliant.
      */
-    if (!MOZ_DOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0))
+    if (!IsFinite(y) && (x == 1.0 || x == -1.0))
         return js_NaN;
     /* pow(x, +-0) is always 1, even for x = NaN (MSVC gets this wrong). */
     if (y == 0)
         return 1;
     return pow(x, y);
 }
 #if defined(_MSC_VER)
 # pragma optimize("", on)
@@ -503,17 +513,17 @@ js_math_pow(JSContext *cx, unsigned argc
         return JS_TRUE;
     }
     if (!ToNumber(cx, vp[2], &x) || !ToNumber(cx, vp[3], &y))
         return JS_FALSE;
     /*
      * 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 (MOZ_DOUBLE_IS_FINITE(x) && x != 0.0) {
+    if (IsFinite(x) && x != 0.0) {
         if (y == 0.5) {
             vp->setNumber(sqrt(x));
             return JS_TRUE;
         }
         if (y == -0.5) {
             vp->setNumber(1.0/sqrt(x));
             return JS_TRUE;
         }
@@ -602,23 +612,23 @@ js_math_round(JSContext *cx, unsigned ar
         return true;
     }
 
     double x;
     if (!ToNumber(cx, args[0], &x))
         return false;
 
     int32_t i;
-    if (MOZ_DOUBLE_IS_INT32(x, &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 (MOZ_DOUBLE_EXPONENT(x) >= 52) {
+    /* 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;
 }
 
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -225,31 +225,31 @@ num_isNaN(JSContext *cx, unsigned argc, 
 {
     if (argc == 0) {
         vp->setBoolean(true);
         return JS_TRUE;
     }
     double x;
     if (!ToNumber(cx, vp[2], &x))
         return false;
-    vp->setBoolean(MOZ_DOUBLE_IS_NaN(x));
+    vp->setBoolean(mozilla::IsNaN(x));
     return JS_TRUE;
 }
 
 static JSBool
 num_isFinite(JSContext *cx, unsigned argc, Value *vp)
 {
     if (argc == 0) {
         vp->setBoolean(false);
         return JS_TRUE;
     }
     double x;
     if (!ToNumber(cx, vp[2], &x))
         return JS_FALSE;
-    vp->setBoolean(MOZ_DOUBLE_IS_FINITE(x));
+    vp->setBoolean(mozilla::IsFinite(x));
     return JS_TRUE;
 }
 
 static JSBool
 num_parseFloat(JSContext *cx, unsigned argc, Value *vp)
 {
     JSString *str;
     double d;
@@ -906,46 +906,46 @@ static const JSFunctionSpec number_metho
 static JSBool
 Number_isNaN(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() < 1 || !args[0].isDouble()) {
         args.rval().setBoolean(false);
         return true;
     }
-    args.rval().setBoolean(MOZ_DOUBLE_IS_NaN(args[0].toDouble()));
+    args.rval().setBoolean(mozilla::IsNaN(args[0].toDouble()));
     return true;
 }
 
 // ES6 draft ES6 15.7.3.11
 static JSBool
 Number_isFinite(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() < 1 || !args[0].isNumber()) {
         args.rval().setBoolean(false);
         return true;
     }
     args.rval().setBoolean(args[0].isInt32() ||
-                           MOZ_DOUBLE_IS_FINITE(args[0].toDouble()));
+                           mozilla::IsFinite(args[0].toDouble()));
     return true;
 }
 
 // ES6 draft ES6 15.7.3.12
 static JSBool
 Number_isInteger(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() < 1 || !args[0].isNumber()) {
         args.rval().setBoolean(false);
         return true;
     }
     Value val = args[0];
     args.rval().setBoolean(val.isInt32() ||
-                           (MOZ_DOUBLE_IS_FINITE(val.toDouble()) &&
+                           (mozilla::IsFinite(val.toDouble()) &&
                             ToInteger(val.toDouble()) == val.toDouble()));
     return true;
 }
 
 // ES6 drafult ES6 15.7.3.13
 static JSBool
 Number_toInteger(JSContext *cx, unsigned argc, Value *vp)
 {
@@ -1026,29 +1026,29 @@ js::InitRuntimeNumberState(JSRuntime *rt
     FIX_FPU();
 
     double d;
 
     /*
      * Our NaN must be one particular canonical value, because we rely on NaN
      * encoding for our value representation.  See Value.h.
      */
-    d = MOZ_DOUBLE_SPECIFIC_NaN(0, 0x8000000000000ULL);
+    d = mozilla::SpecificNaN(0, 0x8000000000000ULL);
     number_constants[NC_NaN].dval = js_NaN = d;
     rt->NaNValue.setDouble(d);
 
-    d = MOZ_DOUBLE_POSITIVE_INFINITY();
+    d = mozilla::PositiveInfinity();
     number_constants[NC_POSITIVE_INFINITY].dval = js_PositiveInfinity = d;
     rt->positiveInfinityValue.setDouble(d);
 
-    d = MOZ_DOUBLE_NEGATIVE_INFINITY();
+    d = mozilla::NegativeInfinity();
     number_constants[NC_NEGATIVE_INFINITY].dval = js_NegativeInfinity = d;
     rt->negativeInfinityValue.setDouble(d);
 
-    number_constants[NC_MIN_VALUE].dval = MOZ_DOUBLE_MIN_VALUE();
+    number_constants[NC_MIN_VALUE].dval = mozilla::MinDoubleValue();
 
     // XXX If ENABLE_INTL_API becomes true all the time at some point,
     //     js::InitRuntimeNumberState is no longer fallible, and we should
     //     change its return type.
 #if !ENABLE_INTL_API
     /* Copy locale-specific separators into the runtime strings. */
     const char *thousandsSeparator, *decimalPoint, *grouping;
 #ifdef HAVE_LOCALECONV
@@ -1166,17 +1166,17 @@ js_InitNumberClass(JSContext *cx, Handle
 }
 
 static char *
 FracNumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base = 10)
 {
 #ifdef DEBUG
     {
         int32_t _;
-        JS_ASSERT(!MOZ_DOUBLE_IS_INT32(d, &_));
+        JS_ASSERT(!mozilla::DoubleIsInt32(d, &_));
     }
 #endif
 
     char* numStr;
     if (base == 10) {
         /*
          * This is V8's implementation of the algorithm described in the
          * following paper:
@@ -1194,17 +1194,17 @@ FracNumberToCString(JSContext *cx, ToCSt
     }
     return numStr;
 }
 
 char *
 js::NumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base/* = 10*/)
 {
     int32_t i;
-    return MOZ_DOUBLE_IS_INT32(d, &i)
+    return mozilla::DoubleIsInt32(d, &i)
            ? IntToCString(cbuf, i, base)
            : FracNumberToCString(cx, cbuf, d, base);
 }
 
 template <AllowGC allowGC>
 static JSString * JS_FASTCALL
 js_NumberToStringWithBase(JSContext *cx, double d, int base)
 {
@@ -1217,17 +1217,17 @@ js_NumberToStringWithBase(JSContext *cx,
      * from the interpreter (which will report the error).
      */
     if (base < 2 || base > 36)
         return NULL;
 
     JSCompartment *c = cx->compartment;
 
     int32_t i;
-    if (MOZ_DOUBLE_IS_INT32(d, &i)) {
+    if (mozilla::DoubleIsInt32(d, &i)) {
         if (base == 10 && StaticStrings::hasInt(i))
             return cx->runtime->staticStrings.getInt(i);
         if (unsigned(i) < unsigned(base)) {
             if (i < 10)
                 return cx->runtime->staticStrings.getInt(i);
             jschar c = 'a' + i - 10;
             JS_ASSERT(StaticStrings::hasUnit(c));
             return cx->runtime->staticStrings.getUnit(c);
@@ -1471,17 +1471,17 @@ js::ToUint16Slow(JSContext *cx, const Va
     JS_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else if (!ToNumberSlow(cx, v, &d)) {
         return false;
     }
 
-    if (d == 0 || !MOZ_DOUBLE_IS_FINITE(d)) {
+    if (d == 0 || !mozilla::IsFinite(d)) {
         *out = 0;
         return true;
     }
 
     uint16_t u = (uint16_t) d;
     if ((double)u == d) {
         *out = u;
         return true;
--- a/js/src/jsnum.h
+++ b/js/src/jsnum.h
@@ -172,17 +172,17 @@ namespace js {
 
 static JS_ALWAYS_INLINE bool
 ValueFitsInInt32(const Value &v, int32_t *pi)
 {
     if (v.isInt32()) {
         *pi = v.toInt32();
         return true;
     }
-    return v.isDouble() && MOZ_DOUBLE_IS_INT32(v.toDouble(), pi);
+    return v.isDouble() && mozilla::DoubleIsInt32(v.toDouble(), pi);
 }
 
 /*
  * Returns true if the given value is definitely an index: that is, the value
  * is a number that's an unsigned 32-bit integer.
  *
  * This method prioritizes common-case speed over accuracy in every case.  It
  * can produce false negatives (but not false positives): some values which are
@@ -193,17 +193,17 @@ static JS_ALWAYS_INLINE bool
 IsDefinitelyIndex(const Value &v, uint32_t *indexp)
 {
     if (v.isInt32() && v.toInt32() >= 0) {
         *indexp = v.toInt32();
         return true;
     }
 
     int32_t i;
-    if (v.isDouble() && MOZ_DOUBLE_IS_INT32(v.toDouble(), &i) && i >= 0) {
+    if (v.isDouble() && mozilla::DoubleIsInt32(v.toDouble(), &i) && i >= 0) {
         *indexp = uint32_t(i);
         return true;
     }
 
     return false;
 }
 
 /* ES5 9.4 ToInteger. */
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -26,16 +26,17 @@
 #include "jsatominlines.h"
 #include "jsboolinlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
+using mozilla::IsFinite;
 using mozilla::Maybe;
 
 Class js::JSONClass = {
     js_JSON_str,
     JSCLASS_HAS_CACHED_PROTO(JSProto_JSON),
     JS_PropertyStub,        /* addProperty */
     JS_DeletePropertyStub,  /* delProperty */
     JS_PropertyStub,        /* getProperty */
@@ -540,17 +541,17 @@ Str(JSContext *cx, const Value &v, Strin
 
     /* Steps 6-7. */
     if (v.isBoolean())
         return v.toBoolean() ? scx->sb.append("true") : scx->sb.append("false");
 
     /* Step 9. */
     if (v.isNumber()) {
         if (v.isDouble()) {
-            if (!MOZ_DOUBLE_IS_FINITE(v.toDouble()))
+            if (!IsFinite(v.toDouble()))
                 return scx->sb.append("null");
         }
 
         StringBuffer sb(cx);
         if (!NumberValueToStringBuffer(cx, v, sb))
             return false;
 
         return scx->sb.append(sb.begin(), sb.length());
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -58,16 +58,18 @@
 #include "vm/String-inl.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 using namespace js::unicode;
 
 using mozilla::CheckedInt;
+using mozilla::IsNaN;
+using mozilla::IsNegativeZero;
 using mozilla::PodCopy;
 using mozilla::PodEqual;
 
 typedef Handle<JSLinearString*> HandleLinearString;
 
 static JSLinearString *
 ArgToRootedString(JSContext *cx, CallArgs &args, unsigned argno)
 {
@@ -1281,17 +1283,17 @@ str_lastIndexOf(JSContext *cx, unsigned 
             if (j <= 0)
                 i = 0;
             else if (j < i)
                 i = j;
         } else {
             double d;
             if (!ToNumber(cx, args[1], &d))
                 return false;
-            if (!MOZ_DOUBLE_IS_NaN(d)) {
+            if (!IsNaN(d)) {
                 d = ToInteger(d);
                 if (d <= 0)
                     i = 0;
                 else if (d < i)
                     i = (int)d;
             }
         }
     }
@@ -3721,17 +3723,17 @@ js::ValueToSource(JSContext *cx, const V
     assertSameCompartment(cx, v);
 
     if (v.isUndefined())
         return cx->names().void0;
     if (v.isString())
         return js_QuoteString(cx, v.toString(), '"');
     if (v.isPrimitive()) {
         /* Special case to preserve negative zero, _contra_ toString. */
-        if (v.isDouble() && MOZ_DOUBLE_IS_NEGATIVE_ZERO(v.toDouble())) {
+        if (v.isDouble() && IsNegativeZero(v.toDouble())) {
             /* NB: _ucNstr rather than _ucstr to indicate non-terminated. */
             static const jschar js_negzero_ucNstr[] = {'-', '0'};
 
             return js_NewStringCopyN<CanGC>(cx, js_negzero_ucNstr, 2);
         }
         return ToString<CanGC>(cx, v);
     }
 
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -40,16 +40,17 @@
 # else
 #  include <sys/mman.h>
 # endif
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
+using mozilla::IsNaN;
 using mozilla::PodCopy;
 
 /*
  * Allocate array buffers with the maximum number of fixed slots marked as
  * reserved, so that the fixed slots may be used for the buffer's contents.
  * The last fixed slot is kept for the object's private data.
  */
 static const uint8_t ARRAYBUFFER_RESERVED_SLOTS = JSObject::MAX_FIXED_SLOTS - 1;
@@ -62,17 +63,17 @@ ValueIsLength(const Value &v, uint32_t *
         if (i < 0)
             return false;
         *len = i;
         return true;
     }
 
     if (v.isDouble()) {
         double d = v.toDouble();
-        if (MOZ_DOUBLE_IS_NaN(d))
+        if (IsNaN(d))
             return false;
 
         uint32_t length = uint32_t(d);
         if (d != double(length))
             return false;
 
         *len = length;
         return true;
@@ -2262,17 +2263,17 @@ class TypedArrayTemplate
 
         return makeInstance(cx, bufobj, byteOffset, length);
     }
 
   protected:
     static NativeType
     nativeFromDouble(double d)
     {
-        if (!ArrayTypeIsFloatingPoint() && JS_UNLIKELY(MOZ_DOUBLE_IS_NaN(d)))
+        if (!ArrayTypeIsFloatingPoint() && JS_UNLIKELY(IsNaN(d)))
             return NativeType(int32_t(0));
         if (TypeIsFloatingPoint<NativeType>())
             return NativeType(d);
         if (TypeIsUnsigned<NativeType>())
             return NativeType(ToUint32(d));
         return NativeType(ToInt32(d));
     }
 
--- a/js/src/methodjit/StubCalls.cpp
+++ b/js/src/methodjit/StubCalls.cpp
@@ -53,16 +53,19 @@
 #include "jsautooplen.h"
 
 using namespace js;
 using namespace js::mjit;
 using namespace js::types;
 using namespace JSC;
 
 using mozilla::DebugOnly;
+using mozilla::DoubleIsInt32;
+using mozilla::IsNaN;
+using mozilla::IsNegative;
 
 void JS_FASTCALL
 stubs::BindName(VMFrame &f, PropertyName *name_)
 {
     RootedPropertyName name(f.cx, name_);
     RootedObject scope(f.cx);
     if (!LookupNameWithGlobalDefault(f.cx, name, f.fp()->scopeChain(), &scope))
         THROW();
@@ -668,23 +671,23 @@ stubs::Div(VMFrame &f)
 
     double d1, d2;
     if (!ToNumber(cx, regs.sp[-2], &d1) || !ToNumber(cx, regs.sp[-1], &d2))
         THROW();
     if (d2 == 0) {
         const Value *vp;
 #ifdef XP_WIN
         /* XXX MSVC miscompiles such that (NaN == 0) */
-        if (MOZ_DOUBLE_IS_NaN(d2))
+        if (IsNaN(d2))
             vp = &rt->NaNValue;
         else
 #endif
-        if (d1 == 0 || MOZ_DOUBLE_IS_NaN(d1))
+        if (d1 == 0 || IsNaN(d1))
             vp = &rt->NaNValue;
-        else if (MOZ_DOUBLE_IS_NEGATIVE(d1) != MOZ_DOUBLE_IS_NEGATIVE(d2))
+        else if (IsNegative(d1) != IsNegative(d2))
             vp = &rt->negativeInfinityValue;
         else
             vp = &rt->positiveInfinityValue;
         regs.sp[-2] = *vp;
         RootedScript fscript(cx, f.script());
         TypeScript::MonitorOverflow(cx, fscript, f.pc());
     } else {
         d1 /= d2;
@@ -1296,17 +1299,17 @@ stubs::TableSwitch(VMFrame &f, jsbytecod
     int32_t tableIdx;
     if (rval.isInt32()) {
         tableIdx = rval.toInt32();
     } else if (rval.isDouble()) {
         double d = rval.toDouble();
         if (d == 0) {
             /* Treat -0 (double) as 0. */
             tableIdx = 0;
-        } else if (!MOZ_DOUBLE_IS_INT32(d, &tableIdx)) {
+        } else if (!DoubleIsInt32(d, &tableIdx)) {
             goto finally;
         }
     } else {
         goto finally;
     }
 
     {
         int32_t low = GET_JUMP_OFFSET(pc);
--- a/js/src/vm/DateTime.cpp
+++ b/js/src/vm/DateTime.cpp
@@ -5,16 +5,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DateTime.h"
 
 #include <time.h>
 
 #include "jsutil.h"
 
+using mozilla::UnspecifiedNaN;
+
 static bool
 ComputeLocalTime(time_t local, struct tm *ptm)
 {
 #ifdef HAVE_LOCALTIME_R
     return localtime_r(&local, ptm);
 #else
     struct tm *otm = localtime(&local);
     if (!otm)
@@ -157,17 +159,17 @@ js::DateTimeInfo::updateTimeZoneAdjustme
  * positive, we can initialize the range at construction time with large
  * negative numbers to ensure the first computation is always a cache miss and
  * doesn't return a bogus offset.
  */
 js::DateTimeInfo::DateTimeInfo()
 {
     // Set to a totally impossible TZA so that the comparison above will fail
     // and all fields will be properly initialized.
-    localTZA_ = MOZ_DOUBLE_NaN();
+    localTZA_ = UnspecifiedNaN();
     updateTimeZoneAdjustment();
 }
 
 int64_t
 js::DateTimeInfo::computeDSTOffsetMilliseconds(int64_t utcSeconds)
 {
     MOZ_ASSERT(utcSeconds >= 0);
     MOZ_ASSERT(utcSeconds <= MaxUnixTimeT);
--- a/js/src/vm/DateTime.h
+++ b/js/src/vm/DateTime.h
@@ -41,17 +41,17 @@ const double StartOfTime = -8.64e15;
 const double EndOfTime = 8.64e15;
 const double MaxTimeMagnitude = 8.64e15;
 
 /* ES5 15.9.1.14. */
 inline double
 TimeClip(double time)
 {
     /* Steps 1-2. */
-    if (!MOZ_DOUBLE_IS_FINITE(time) || mozilla::Abs(time) > MaxTimeMagnitude)
+    if (!mozilla::IsFinite(time) || mozilla::Abs(time) > MaxTimeMagnitude)
         return js_NaN;
 
     /* Step 3. */
     return ToInteger(time + (+0.0));
 }
 
 /*
  * Stores date/time information, particularly concerning the current local
--- a/js/src/vm/NumericConversions.h
+++ b/js/src/vm/NumericConversions.h
@@ -130,17 +130,17 @@ ToIntWidth(double d)
         twoWidth.s.lo = 0;
         du.d -= twoWidth.d;
     }
 
     return ResultType(du.d);
 #else
     double twoWidth, twoWidthMin1;
 
-    if (!MOZ_DOUBLE_IS_FINITE(d))
+    if (!mozilla::IsFinite(d))
         return 0;
 
     /* FIXME: This relies on undefined behavior; see bug 667739. */
     ResultType i = (ResultType) d;
     if ((double) i == d)
         return ResultType(i);
 
     twoWidth = width == 32 ? 4294967296.0 : 18446744073709551616.0;
@@ -304,18 +304,18 @@ ToUint64(double d)
 
 /* ES5 9.4 ToInteger (specialized for doubles). */
 inline double
 ToInteger(double d)
 {
     if (d == 0)
         return d;
 
-    if (!MOZ_DOUBLE_IS_FINITE(d)) {
-        if (MOZ_DOUBLE_IS_NaN(d))
+    if (!mozilla::IsFinite(d)) {
+        if (mozilla::IsNaN(d))
             return 0;
         return d;
     }
 
     bool neg = (d < 0);
     d = floor(neg ? -d : d);
     return neg ? -d : d;
 }
--- a/js/xpconnect/src/dictionary_helper_gen.py
+++ b/js/xpconnect/src/dictionary_helper_gen.py
@@ -239,19 +239,19 @@ def init_value(attribute):
             return ""
         if realtype.count("nsACString"):
             return ""
         if realtype.count("JS::Value"):
             return "JSVAL_VOID"
         return "0"
     else:
         if realtype.count("double") and attribute.defvalue == "Infinity":
-            return "MOZ_DOUBLE_POSITIVE_INFINITY()"
+            return "mozilla::PositiveInfinity()"
         if realtype.count("double") and attribute.defvalue == "-Infinity":
-            return "MOZ_DOUBLE_NEGATIVE_INFINITY()"
+            return "mozilla::NegativeInfinity()"
         if realtype.count("nsAString"):
             return "NS_LITERAL_STRING(\"%s\")" % attribute.defvalue
         if realtype.count("nsACString"):
             return "NS_LITERAL_CSTRING(\"%s\")" % attribute.defvalue
         raise xpidl.IDLError("Default value of %s is not supported for type %s" %
                              (attribute.defvalue, realtype), attribute.location)
 
 def write_header(iface, fd):
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -37,17 +37,17 @@ nsCSSValue::nsCSSValue(int32_t aValue, n
 }
 
 nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit)
   : mUnit(aUnit)
 {
   NS_ABORT_IF_FALSE(eCSSUnit_Percent <= aUnit, "not a float value");
   if (eCSSUnit_Percent <= aUnit) {
     mValue.mFloat = aValue;
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+    MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
   }
   else {
     mUnit = eCSSUnit_Null;
     mValue.mInt = 0;
   }
 }
 
 nsCSSValue::nsCSSValue(const nsString& aValue, nsCSSUnit aUnit)
@@ -100,17 +100,17 @@ nsCSSValue::nsCSSValue(nsCSSValueGradien
 nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
   : mUnit(aCopy.mUnit)
 {
   if (mUnit <= eCSSUnit_DummyInherit) {
     // nothing to do, but put this important case first
   }
   else if (eCSSUnit_Percent <= mUnit) {
     mValue.mFloat = aCopy.mValue.mFloat;
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+    MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
   }
   else if (UnitHasStringValue()) {
     mValue.mString = aCopy.mValue.mString;
     mValue.mString->AddRef();
   }
   else if (eCSSUnit_Integer <= mUnit && mUnit <= eCSSUnit_EnumColor) {
     mValue.mInt = aCopy.mValue.mInt;
   }
@@ -318,27 +318,27 @@ void nsCSSValue::SetIntValue(int32_t aVa
   }
 }
 
 void nsCSSValue::SetPercentValue(float aValue)
 {
   Reset();
   mUnit = eCSSUnit_Percent;
   mValue.mFloat = aValue;
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+  MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
 }
 
 void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit)
 {
   NS_ABORT_IF_FALSE(eCSSUnit_Number <= aUnit, "not a float value");
   Reset();
   if (eCSSUnit_Number <= aUnit) {
     mUnit = aUnit;
     mValue.mFloat = aValue;
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+    MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
   }
 }
 
 void nsCSSValue::SetStringValue(const nsString& aValue,
                                 nsCSSUnit aUnit)
 {
   Reset();
   mUnit = aUnit;
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* representation of simple property values within CSS declarations */
 
 #ifndef nsCSSValue_h___
 #define nsCSSValue_h___
 
 #include "mozilla/Attributes.h"
+#include "mozilla/FloatingPoint.h"
 
 #include "nsCOMPtr.h"
 #include "nsCRTGlue.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsRefPtrHashtable.h"
 #include "nsString.h"
 #include "nsStringBuffer.h"
 #include "nsTArray.h"
 #include "nsStyleConsts.h"
-#include "mozilla/FloatingPoint.h"
 
 class imgRequestProxy;
 class nsIDocument;
 class nsIPrincipal;
 class nsPresContext;
 class nsIURI;
 template <class T>
 class nsPtrHashKey;
@@ -350,17 +350,17 @@ public:
   {
     NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Percent, "not a percent value");
     return mValue.mFloat;
   }
 
   float GetFloatValue() const
   {
     NS_ABORT_IF_FALSE(eCSSUnit_Number <= mUnit, "not a float value");
-    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+    MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
     return mValue.mFloat;
   }
 
   float GetAngleValue() const
   {
     NS_ABORT_IF_FALSE(eCSSUnit_Degree <= mUnit &&
                  mUnit <= eCSSUnit_Turn, "not an angle value");
     return mValue.mFloat;
--- a/layout/style/nsStyleAnimation.cpp
+++ b/layout/style/nsStyleAnimation.cpp
@@ -878,23 +878,23 @@ EnsureNotNan(T aValue)
 {
   return aValue;
 }
 template<>
 MOZ_ALWAYS_INLINE float
 EnsureNotNan(float aValue)
 {
   // This would benefit from a MOZ_FLOAT_IS_NaN if we had one.
-  return MOZ_LIKELY(!MOZ_DOUBLE_IS_NaN(aValue)) ? aValue : 0;
+  return MOZ_LIKELY(!mozilla::IsNaN(aValue)) ? aValue : 0;
 }
 template<>
 MOZ_ALWAYS_INLINE double
 EnsureNotNan(double aValue)
 {
-  return MOZ_LIKELY(!MOZ_DOUBLE_IS_NaN(aValue)) ? aValue : 0;
+  return MOZ_LIKELY(!mozilla::IsNaN(aValue)) ? aValue : 0;
 }
 
 template <typename T>
 T
 RestrictValue(uint32_t aRestrictions, T aValue)
 {
   T result = EnsureNotNan(aValue);
   switch (aRestrictions) {
@@ -3214,24 +3214,24 @@ nsStyleAnimation::Value::Value(nscoord a
   mUnit = eUnit_Coord;
   mValue.mCoord = aLength;
 }
 
 nsStyleAnimation::Value::Value(float aPercent, PercentConstructorType)
 {
   mUnit = eUnit_Percent;
   mValue.mFloat = aPercent;
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+  MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
 }
 
 nsStyleAnimation::Value::Value(float aFloat, FloatConstructorType)
 {
   mUnit = eUnit_Float;
   mValue.mFloat = aFloat;
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+  MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
 }
 
 nsStyleAnimation::Value::Value(nscolor aColor, ColorConstructorType)
 {
   mUnit = eUnit_Color;
   mValue.mColor = aColor;
 }
 
@@ -3253,17 +3253,17 @@ nsStyleAnimation::Value::operator=(const
       mValue.mInt = aOther.mValue.mInt;
       break;
     case eUnit_Coord:
       mValue.mCoord = aOther.mValue.mCoord;
       break;
     case eUnit_Percent:
     case eUnit_Float:
       mValue.mFloat = aOther.mValue.mFloat;
-      MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+      MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
       break;
     case eUnit_Color:
       mValue.mColor = aOther.mValue.mColor;
       break;
     case eUnit_Calc:
       NS_ABORT_IF_FALSE(aOther.mValue.mCSSValue, "values may not be null");
       mValue.mCSSValue = new nsCSSValue(*aOther.mValue.mCSSValue);
       if (!mValue.mCSSValue) {
@@ -3365,26 +3365,26 @@ nsStyleAnimation::Value::SetCoordValue(n
 }
 
 void
 nsStyleAnimation::Value::SetPercentValue(float aPercent)
 {
   FreeValue();
   mUnit = eUnit_Percent;
   mValue.mFloat = aPercent;
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+  MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
 }
 
 void
 nsStyleAnimation::Value::SetFloatValue(float aFloat)
 {
   FreeValue();
   mUnit = eUnit_Float;
   mValue.mFloat = aFloat;
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(mValue.mFloat));
+  MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
 }
 
 void
 nsStyleAnimation::Value::SetColorValue(nscolor aColor)
 {
   FreeValue();
   mUnit = eUnit_Color;
   mValue.mColor = aColor;
--- a/mfbt/FloatingPoint.h
+++ b/mfbt/FloatingPoint.h
@@ -7,238 +7,226 @@
 
 #ifndef mozilla_FloatingPoint_h_
 #define mozilla_FloatingPoint_h_
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/StandardInteger.h"
 
+namespace mozilla {
+
 /*
  * It's reasonable to ask why we have this header at all.  Don't isnan,
  * copysign, the built-in comparison operators, and the like solve these
  * problems?  Unfortunately, they don't.  We've found that various compilers
  * (MSVC, MSVC when compiling with PGO, and GCC on OS X, at least) miscompile
  * the standard methods in various situations, so we can't use them.  Some of
  * these compilers even have problems compiling seemingly reasonable bitwise
  * algorithms!  But with some care we've found algorithms that seem to not
  * trigger those compiler bugs.
  *
  * For the aforementioned reasons, be very wary of making changes to any of
  * these algorithms.  If you must make changes, keep a careful eye out for
  * compiler bustage, particularly PGO-specific bustage.
- *
- * Some users require that this file be C-compatible.  Unfortunately, this means
- * no mozilla namespace to contain everything, no detail namespace clarifying
- * MozDoublePun to be an internal data structure, and so on.
  */
 
 /*
  * These implementations all assume |double| is a 64-bit double format number
  * type, compatible with the IEEE-754 standard.  C/C++ don't require this to be
  * the case.  But we required this in implementations of these algorithms that
  * preceded this header, so we shouldn't break anything if we continue doing so.
  */
 MOZ_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t), "double must be 64 bits");
 
-/*
- * Constant expressions in C can't refer to consts, unfortunately, so #define
- * these rather than use |const uint64_t|.
- */
-#define MOZ_DOUBLE_SIGN_BIT          0x8000000000000000ULL
-#define MOZ_DOUBLE_EXPONENT_BITS     0x7ff0000000000000ULL
-#define MOZ_DOUBLE_SIGNIFICAND_BITS  0x000fffffffffffffULL
+const unsigned DoubleExponentBias = 1023;
+const unsigned DoubleExponentShift = 52;
+
+namespace detail {
 
-#define MOZ_DOUBLE_EXPONENT_BIAS   1023
-#define MOZ_DOUBLE_EXPONENT_SHIFT  52
+const uint64_t DoubleSignBit         = 0x8000000000000000ULL;
+const uint64_t DoubleExponentBits    = 0x7ff0000000000000ULL;
+const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL;
 
-MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT & MOZ_DOUBLE_EXPONENT_BITS) == 0,
+MOZ_STATIC_ASSERT((DoubleSignBit & DoubleExponentBits) == 0,
                   "sign bit doesn't overlap exponent bits");
-MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT & MOZ_DOUBLE_SIGNIFICAND_BITS) == 0,
+MOZ_STATIC_ASSERT((DoubleSignBit & DoubleSignificandBits) == 0,
                   "sign bit doesn't overlap significand bits");
-MOZ_STATIC_ASSERT((MOZ_DOUBLE_EXPONENT_BITS & MOZ_DOUBLE_SIGNIFICAND_BITS) == 0,
+MOZ_STATIC_ASSERT((DoubleExponentBits & DoubleSignificandBits) == 0,
                   "exponent bits don't overlap significand bits");
 
-MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT | MOZ_DOUBLE_EXPONENT_BITS | MOZ_DOUBLE_SIGNIFICAND_BITS)
-                  == ~(uint64_t)0,
+MOZ_STATIC_ASSERT((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) ==
+                  ~uint64_t(0),
                   "all bits accounted for");
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * This union is NOT a public data structure, and it is not to be used outside
- * this file!
- */
-union MozDoublePun {
+union DoublePun
+{
     /*
      * Every way to pun the bits of a double introduces an additional layer of
      * complexity, across a multitude of platforms, architectures, and ABIs.
      * Use *only* uint64_t to reduce complexity.  Don't add new punning here
      * without discussion!
      */
     uint64_t u;
     double d;
 };
 
+} /* namespace detail */
+
 /** Determines whether a double is NaN. */
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_NaN(double d)
+static MOZ_ALWAYS_INLINE bool
+IsNaN(double d)
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
   pun.d = d;
 
   /*
    * A double is NaN if all exponent bits are 1 and the significand contains at
    * least one non-zero bit.
    */
-  return (pun.u & MOZ_DOUBLE_EXPONENT_BITS) == MOZ_DOUBLE_EXPONENT_BITS &&
-         (pun.u & MOZ_DOUBLE_SIGNIFICAND_BITS) != 0;
+  return (pun.u & detail::DoubleExponentBits) == detail::DoubleExponentBits &&
+         (pun.u & detail::DoubleSignificandBits) != 0;
 }
 
 /** Determines whether a double is +Infinity or -Infinity. */
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_INFINITE(double d)
+static MOZ_ALWAYS_INLINE bool
+IsInfinite(double d)
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
   pun.d = d;
 
   /* Infinities have all exponent bits set to 1 and an all-0 significand. */
-  return (pun.u & ~MOZ_DOUBLE_SIGN_BIT) == MOZ_DOUBLE_EXPONENT_BITS;
+  return (pun.u & ~detail::DoubleSignBit) == detail::DoubleExponentBits;
 }
 
 /** Determines whether a double is not NaN or infinite. */
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_FINITE(double d)
+static MOZ_ALWAYS_INLINE bool
+IsFinite(double d)
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
   pun.d = d;
 
   /*
    * NaN and Infinities are the only non-finite doubles, and both have all
    * exponent bits set to 1.
    */
-  return (pun.u & MOZ_DOUBLE_EXPONENT_BITS) != MOZ_DOUBLE_EXPONENT_BITS;
+  return (pun.u & detail::DoubleExponentBits) != detail::DoubleExponentBits;
 }
 
 /**
  * Determines whether a double is negative.  It is an error to call this method
  * on a double which is NaN.
  */
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_NEGATIVE(double d)
+static MOZ_ALWAYS_INLINE bool
+IsNegative(double d)
 {
-  union MozDoublePun pun;
+  MOZ_ASSERT(!IsNaN(d), "NaN does not have a sign");
+
+  union detail::DoublePun pun;
   pun.d = d;
 
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(d), "NaN does not have a sign");
-
   /* The sign bit is set if the double is negative. */
-  return (pun.u & MOZ_DOUBLE_SIGN_BIT) != 0;
+  return (pun.u & detail::DoubleSignBit) != 0;
 }
 
 /** Determines whether a double represents -0. */
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_NEGATIVE_ZERO(double d)
+static MOZ_ALWAYS_INLINE bool
+IsNegativeZero(double d)
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
   pun.d = d;
 
   /* Only the sign bit is set if the double is -0. */
-  return pun.u == MOZ_DOUBLE_SIGN_BIT;
+  return pun.u == detail::DoubleSignBit;
 }
 
 /** Returns the exponent portion of the double. */
 static MOZ_ALWAYS_INLINE int_fast16_t
-MOZ_DOUBLE_EXPONENT(double d)
+ExponentComponent(double d)
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
   pun.d = d;
 
   /*
    * The exponent component of a double is an unsigned number, biased from its
    * actual value.  Subtract the bias to retrieve the actual exponent.
    */
-  return (int_fast16_t)((pun.u & MOZ_DOUBLE_EXPONENT_BITS) >> MOZ_DOUBLE_EXPONENT_SHIFT) -
-                        MOZ_DOUBLE_EXPONENT_BIAS;
+  return int_fast16_t((pun.u & detail::DoubleExponentBits) >> DoubleExponentShift) -
+         int_fast16_t(DoubleExponentBias);
 }
 
 /** Returns +Infinity. */
 static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_POSITIVE_INFINITY()
+PositiveInfinity()
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
 
   /*
    * Positive infinity has all exponent bits set, sign bit set to 0, and no
    * significand.
    */
-  pun.u = MOZ_DOUBLE_EXPONENT_BITS;
+  pun.u = detail::DoubleExponentBits;
   return pun.d;
 }
 
 /** Returns -Infinity. */
 static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_NEGATIVE_INFINITY()
+NegativeInfinity()
 {
-  union MozDoublePun pun;
+  union detail::DoublePun pun;
 
   /*
    * Negative infinity has all exponent bits set, sign bit set to 1, and no
    * significand.
    */
-  pun.u = MOZ_DOUBLE_SIGN_BIT | MOZ_DOUBLE_EXPONENT_BITS;
+  pun.u = detail::DoubleSignBit | detail::DoubleExponentBits;
   return pun.d;
 }
 
 /** Constructs a NaN value with the specified sign bit and significand bits. */
 static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_SPECIFIC_NaN(int signbit, uint64_t significand)
+SpecificNaN(int signbit, uint64_t significand)
 {
-  union MozDoublePun pun;
-
   MOZ_ASSERT(signbit == 0 || signbit == 1);
-  MOZ_ASSERT((significand & ~MOZ_DOUBLE_SIGNIFICAND_BITS) == 0);
-  MOZ_ASSERT(significand & MOZ_DOUBLE_SIGNIFICAND_BITS);
+  MOZ_ASSERT((significand & ~detail::DoubleSignificandBits) == 0);
+  MOZ_ASSERT(significand & detail::DoubleSignificandBits);
+
+  union detail::DoublePun pun;
+  pun.u = (signbit ? detail::DoubleSignBit : 0) |
+          detail::DoubleExponentBits |
+          significand;
+  MOZ_ASSERT(IsNaN(pun.d));
+  return pun.d;
+}
 
-  pun.u = (signbit ? MOZ_DOUBLE_SIGN_BIT : 0) |
-          MOZ_DOUBLE_EXPONENT_BITS |
-          significand;
-  MOZ_ASSERT(MOZ_DOUBLE_IS_NaN(pun.d));
+/** Computes the smallest non-zero positive double value. */
+static MOZ_ALWAYS_INLINE double
+MinDoubleValue()
+{
+  union detail::DoublePun pun;
+  pun.u = 1;
   return pun.d;
 }
 
+static MOZ_ALWAYS_INLINE bool
+DoubleIsInt32(double d, int32_t* i)
+{
+  /*
+   * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces
+   *     undefined behavior.  We should definitely fix this (bug 744965), but as
+   *     apparently it "works" in practice, it's not a pressing concern now.
+   */
+  return !IsNegativeZero(d) && d == (*i = int32_t(d));
+}
+
 /**
  * Computes a NaN value.  Do not use this method if you depend upon a particular
  * NaN value being returned.
  */
 static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_NaN()
+UnspecifiedNaN()
 {
-  return MOZ_DOUBLE_SPECIFIC_NaN(0, 0xfffffffffffffULL);
-}
-
-/** Computes the smallest non-zero positive double value. */
-static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_MIN_VALUE()
-{
-  union MozDoublePun pun;
-  pun.u = 1;
-  return pun.d;
+  return mozilla::SpecificNaN(0, 0xfffffffffffffULL);
 }
 
-static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_INT32(double d, int32_t* i)
-{
-  /*
-   * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces
-   *     undefined behavior.  We should definitely fix this (bug 744965), but as
-   *     apparently it "works" in practice, it's not a pressing concern now.
-   */
-  return !MOZ_DOUBLE_IS_NEGATIVE_ZERO(d) && d == (*i = (int32_t)d);
-}
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
+} /* namespace mozilla */
 
 #endif  /* mozilla_FloatingPoint_h_ */
--- a/mfbt/decimal/moz-decimal-utils.h
+++ b/mfbt/decimal/moz-decimal-utils.h
@@ -36,33 +36,33 @@
 
 #define WTF_MAKE_NONCOPYABLE(ClassName) \
   private: \
     ClassName(const ClassName&) MOZ_DELETE; \
     void operator=(const ClassName&) MOZ_DELETE;
 
 #if defined(_MSC_VER) && (_MSC_VER <= 1700)
 namespace std {
-  inline bool isinf(double num) { return MOZ_DOUBLE_IS_INFINITE(num); }
-  inline bool isnan(double num) { return MOZ_DOUBLE_IS_NaN(num); }
-  inline bool isfinite(double num) { return MOZ_DOUBLE_IS_FINITE(num); }
+  inline bool isinf(double num) { return mozilla::IsInfinite(num); }
+  inline bool isnan(double num) { return mozilla::IsNaN(num); }
+  inline bool isfinite(double num) { return mozilla::IsFinite(num); }
 }
 #endif
 
 typedef std::string String;
 
 double mozToDouble(const String &aStr, bool *valid) {
   double_conversion::StringToDoubleConverter converter(
     double_conversion::StringToDoubleConverter::NO_FLAGS,
-    MOZ_DOUBLE_NaN(), MOZ_DOUBLE_NaN(), nullptr, nullptr);
+    mozilla::UnspecifiedNaN(), mozilla::UnspecifiedNaN(), nullptr, nullptr);
   const char* str = aStr.c_str();
   int length = mozilla::SafeCast<int>(strlen(str));
   int processed_char_count; // unused - NO_FLAGS requires the whole string to parse
   double result = converter.StringToDouble(str, length, &processed_char_count);
-  *valid = MOZ_DOUBLE_IS_FINITE(result);
+  *valid = mozilla::IsFinite(result);
   return result;
 }
 
 String mozToString(double aNum) {
   char buffer[64];
   int buffer_length = mozilla::ArrayLength(buffer);
   const double_conversion::DoubleToStringConverter& converter =
     double_conversion::DoubleToStringConverter::EcmaScriptConverter();