Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Unified Diff: sdk/lib/math/math.dart

Issue 19638002: Remove explicit argument type checks in math min and max. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/math/math.dart
===================================================================
--- sdk/lib/math/math.dart (revision 25101)
+++ sdk/lib/math/math.dart (working copy)
@@ -58,32 +58,24 @@
* is returned.
*/
num min(num a, num b) {
- if (a is num) {
- // TODO(floitsch): merge this if into the previous one, once dart2js
- // correctly propagates types for logical ands.
- if (b is num) {
- if (a > b) return b;
- if (a < b) return a;
- if (b is double) {
- // Special case for NaN and -0.0. If one argument is NaN return NaN.
- // [min] must also distinguish between -0.0 and 0.0.
- if (a is double) {
- if (a == 0.0) {
- // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN.
- // The following returns -0.0 if either a or b is -0.0, and it
- // returns NaN if b is NaN.
- return (a + b) * a * b;
- }
- }
- // Check for NaN and b == -0.0.
- if (a == 0 && b.isNegative || b.isNaN) return b;
- return a;
+ if (a > b) return b;
+ if (a < b) return a;
+ if (b is double) {
+ // Special case for NaN and -0.0. If one argument is NaN return NaN.
+ // [min] must also distinguish between -0.0 and 0.0.
+ if (a is double) {
+ if (a == 0.0) {
+ // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN.
+ // The following returns -0.0 if either a or b is -0.0, and it
+ // returns NaN if b is NaN.
+ return (a + b) * a * b;
}
- return a;
}
- throw new ArgumentError(b);
+ // Check for NaN and b == -0.0.
+ if (a == 0 && b.isNegative || b.isNaN) return b;
+ return a;
}
- throw new ArgumentError(a);
+ return a;
}
/**
@@ -95,34 +87,26 @@
* then it is unspecified which of the two arguments is returned.
*/
num max(num a, num b) {
- if (a is num) {
- // TODO(floitsch): merge this if into the previous one, once dart2js
- // correctly propagates types for logical ands.
- if (b is num) {
- if (a > b) return a;
- if (a < b) return b;
- if (b is double) {
- // Special case for NaN and -0.0. If one argument is NaN return NaN.
- // [max] must also distinguish between -0.0 and 0.0.
- if (a is double) {
- if (a == 0.0) {
- // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN.
- // The following returns 0.0 if either a or b is 0.0, and it
- // returns NaN if b is NaN.
- return a + b;
- }
- }
- // Check for NaN.
- if (b.isNaN) return b;
- return a;
+ if (a > b) return a;
+ if (a < b) return b;
+ if (b is double) {
+ // Special case for NaN and -0.0. If one argument is NaN return NaN.
+ // [max] must also distinguish between -0.0 and 0.0.
+ if (a is double) {
+ if (a == 0.0) {
+ // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN.
+ // The following returns 0.0 if either a or b is 0.0, and it
+ // returns NaN if b is NaN.
+ return a + b;
}
- // max(-0.0, 0) must return 0.
- if (b == 0 && a.isNegative) return b;
- return a;
}
- throw new ArgumentError(b);
+ // Check for NaN.
+ if (b.isNaN) return b;
+ return a;
}
- throw new ArgumentError(a);
+ // max(-0.0, 0) must return 0.
+ if (b == 0 && a.isNegative) return b;
+ return a;
}
/**
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698