diff --git a/runtime/lib/double.dart b/runtime/lib/double.dart index 10bda5de1a6..012ffc5f38e 100644 --- a/runtime/lib/double.dart +++ b/runtime/lib/double.dart @@ -103,6 +103,8 @@ class Double implements double { bool isNaN() native "Double_isNaN"; double abs() { + // Handle negative 0.0. + if (this == 0.0) return 0.0; return this < 0.0 ? -this : this; } @@ -139,7 +141,7 @@ class Double implements double { String s = ""; // Step 6. - if (x.isNegative()) { + if (x.isNegative() && x != 0.0) { s = "-"; x = -x; } @@ -192,9 +194,30 @@ class Double implements double { String toRadixString(int radix) { throw "Double.toRadixString unimplemented."; } + + // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. int compareTo(Comparable other) { - if (this == other) return 0; - if (this < other) return -1; - return 1; + final int EQUAL = 0, LESS = -1, GREATER = 1; + if (this < other) { + return LESS; + } else if (this > other) { + return GREATER; + } else if (this == other) { + if (this == 0.0) { + bool thisIsNegative = isNegative(); + bool otherIsNegative = other.isNegative(); + if (thisIsNegative == otherIsNegative) { + return EQUAL; + } + return thisIsNegative ? LESS : GREATER; + } else { + return EQUAL; + } + } else if (isNaN()) { + return other.isNaN() ? EQUAL : GREATER; + } else { + // Other is NaN. + return LESS; + } } } diff --git a/runtime/vm/ast.cc b/runtime/vm/ast.cc index 15117c173ce..6de5e519ba6 100644 --- a/runtime/vm/ast.cc +++ b/runtime/vm/ast.cc @@ -93,8 +93,8 @@ AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { Double& dbl = Double::Handle(); dbl ^= literal().raw(); // Preserve negative zero. - const Instance& literal = - Instance::ZoneHandle(Double::New(0.0 - dbl.value())); + double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); + const Instance& literal = Instance::ZoneHandle(Double::New(new_value)); return new LiteralNode(this->token_index(), literal); } } diff --git a/tests/co19/co19-runtime.status b/tests/co19/co19-runtime.status index bf8df23ef45..97384b674dc 100644 --- a/tests/co19/co19-runtime.status +++ b/tests/co19/co19-runtime.status @@ -4,6 +4,7 @@ prefix co19 + # Flaky tests, see http://code.google.com/p/co19/issues/detail?id=4 LibTest/core/StopWatch/elapsedInMs/StopWatch/elapsedInMs/A01/t01: Skip LibTest/core/StopWatch/elapsedInUs/StopWatch/elapsedInUs/A01/t01: Skip @@ -12,6 +13,12 @@ LibTest/core/StopWatch/stop/StopWatch/stop/A01/t01: Skip [ $component == vm ] + +LibTest/core/double/isNegative/double/isNegative/A01/t01: Fail # Issue 6 +LibTest/core/double/operatorDivision/double/operatorDivision/A01/t05: Fail # Issue 7 +LibTest/core/double/operator~div/double/operator~div/A01/t05: Fail # Issue 7 +LibTest/core/Math/atan2/Math/atan2/A01/t03: Fail # Issue 8 + LangGuideTest/02_Language_Constructs/02_1_Class/02_1_Class_Const_Expressions/A04/t01: Fail # Bug 5371433 LangGuideTest/02_Language_Constructs/02_1_Class/02_1_Class_Construction/A10/t01: Fail # Bug 5371433 LangGuideTest/02_Language_Constructs/02_5_Meaning_of_Names/Examples/A02/t01: Fail # Bug 5371433 @@ -70,7 +77,6 @@ LibTest/core/Queue/some/Queue/some/A01/t06: Fail LibTest/core/RegExp/firstMatch/Pattern_semantics/15.10.2.10_CharacterEscape/RegExp/firstMatch/CharacterEscape/A06/t02: Fail LibTest/core/StringBuffer/isEmpty/StringBuffer/isEmpty/A01/t01: Fail - # List.fromList has been removed. LibTest/core/List/List.fromList/*: Fail @@ -214,8 +220,6 @@ LibTest/core/StringBuffer/add/StringBuffer/add/A02/t01: Fail LibTest/core/Strings/concatAll/Strings/concatAll/A03/t01: crash LibTest/core/Strings/join/Strings/join/A03/t01: crash LibTest/core/TypeError/srcType/TypeError/srcType/A01/t01: Fail -LibTest/core/double/compareTo/double/compareTo/A01/t02: Fail -LibTest/core/double/compareTo/double/compareTo/A01/t03: Fail LibTest/core/double/isOdd/double/isOdd/A01/t02: Fail LibTest/core/double/operator%/double/operator%/A01/t06: Fail LibTest/core/double/operatorAddition/double/operatorAddition/A01/t02: Fail diff --git a/tests/corelib/corelib.status b/tests/corelib/corelib.status index d9541149735..b083b8c3117 100644 --- a/tests/corelib/corelib.status +++ b/tests/corelib/corelib.status @@ -6,7 +6,6 @@ prefix corelib [ $component == vm || $component == dartium ] UnicodeTest: Fail # Bug 5163868 -DoubleCompareTest: Fail # Bug 5427703 *DartcTest: Skip [ $arch == ia32 ]