mfbt/decimal/comparison-with-nan.patch

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 diff --git a/mfbt/decimal/Decimal.cpp b/mfbt/decimal/Decimal.cpp
     2 --- a/mfbt/decimal/Decimal.cpp
     3 +++ b/mfbt/decimal/Decimal.cpp
     4 @@ -505,21 +505,25 @@ Decimal Decimal::operator/(const Decimal
     5      if (remainder > divisor / 2)
     6          ++result;
     8      return Decimal(resultSign, resultExponent, result);
     9  }
    11  bool Decimal::operator==(const Decimal& rhs) const
    12  {
    13 +    if (isNaN() || rhs.isNaN())
    14 +        return false;
    15      return m_data == rhs.m_data || compareTo(rhs).isZero();
    16  }
    18  bool Decimal::operator!=(const Decimal& rhs) const
    19  {
    20 +    if (isNaN() || rhs.isNaN())
    21 +        return true;
    22      if (m_data == rhs.m_data)
    23          return false;
    24      const Decimal result = compareTo(rhs);
    25      if (result.isNaN())
    26          return false;
    27      return !result.isZero();
    28  }
    30 @@ -528,16 +532,18 @@ bool Decimal::operator<(const Decimal& r
    31      const Decimal result = compareTo(rhs);
    32      if (result.isNaN())
    33          return false;
    34      return !result.isZero() && result.isNegative();
    35  }
    37  bool Decimal::operator<=(const Decimal& rhs) const
    38  {
    39 +    if (isNaN() || rhs.isNaN())
    40 +        return false;
    41      if (m_data == rhs.m_data)
    42          return true;
    43      const Decimal result = compareTo(rhs);
    44      if (result.isNaN())
    45          return false;
    46      return result.isZero() || result.isNegative();
    47  }
    49 @@ -546,16 +552,18 @@ bool Decimal::operator>(const Decimal& r
    50      const Decimal result = compareTo(rhs);
    51      if (result.isNaN())
    52          return false;
    53      return !result.isZero() && result.isPositive();
    54  }
    56  bool Decimal::operator>=(const Decimal& rhs) const
    57  {
    58 +    if (isNaN() || rhs.isNaN())
    59 +        return false;
    60      if (m_data == rhs.m_data)
    61          return true;
    62      const Decimal result = compareTo(rhs);
    63      if (result.isNaN())
    64          return false;
    65      return result.isZero() || !result.isNegative();
    66  }

mercurial