Fix issue: 5427703 (compareTo), fix parsing of -0.0.

Review URL: http://codereview.chromium.org//8430037

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1156 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
srdjan@google.com
2011-11-03 18:03:39 +00:00
parent 3dedc560f5
commit 49caedb014
4 changed files with 36 additions and 10 deletions
+27 -4
View File
@@ -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;
}
}
}
+2 -2
View File
@@ -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);
}
}
+7 -3
View File
@@ -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
-1
View File
@@ -6,7 +6,6 @@ prefix corelib
[ $component == vm || $component == dartium ]
UnicodeTest: Fail # Bug 5163868
DoubleCompareTest: Fail # Bug 5427703
*DartcTest: Skip
[ $arch == ia32 ]