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

Side by Side Diff: corelib/unified/math/base.dart

Issue 10702204: Revert "Allow patch files to add top-level declarations to the patched library." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | corelib/unified/math/random.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // A part of the dart:math library. 5 // A part of the dart:math library.
6 6
7 /** 7 /**
8 * Base of the natural logarithms. 8 * Base of the natural logarithms.
9 */ 9 */
10 final double E = 2.718281828459045; 10 final double E = 2.718281828459045;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 */ 51 */
52 external int parseInt(String str); 52 external int parseInt(String str);
53 53
54 /** 54 /**
55 * Parses a [String] representation of a [double], and returns 55 * Parses a [String] representation of a [double], and returns
56 * a [double]. Throws a [BadNumberFormatException] if [str] cannot 56 * a [double]. Throws a [BadNumberFormatException] if [str] cannot
57 * be parsed as a [double]. 57 * be parsed as a [double].
58 */ 58 */
59 external double parseDouble(String str); 59 external double parseDouble(String str);
60 60
61 /**
62 * Returns the minimum of two numbers. If either argument is NaN returns NaN.
63 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are
64 * equal (int and doubles with the same mathematical value are equal) then
65 * it is unspecified which of the two arguments is returned.
66 */
67 num min(num a, num b) { 61 num min(num a, num b) {
68 if (a is num) { 62 int c = a.compareTo(b);
69 // TODO(floitsch): merge this if into the previous one, once dart2js 63 if (c == 0) return a;
70 // correctly propagates types for logical ands. 64 if (c < 0) {
71 if (b is num) { 65 if ((b is double) && b.isNaN()) return b;
72 if (a > b) return b; 66 return a;
73 if (a < b) return a;
74 if (b is double) {
75 // Special case for NaN and -0.0. If one argument is NaN return NaN.
76 // [min] must also distinguish between -0.0 and 0.0.
77 if (a is double) {
78 if (a == 0.0) {
79 // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN.
80 // The following returns -0.0 if either a or b is -0.0, and it
81 // returns NaN if b is NaN.
82 return (a + b) * a * b;
83 }
84 }
85 // Check for NaN and b == -0.0.
86 if (a == 0 && b.isNegative() || b.isNaN()) return b;
87 return a;
88 }
89 return a;
90 }
91 throw new IllegalArgumentException(b);
92 } 67 }
93 throw new IllegalArgumentException(a); 68 if ((a is double) && a.isNaN()) return a;
69 return b;
70 }
71
72 num max(num a, num b) {
73 // NaNs are handled correctly since the compareTo function always considers
74 // them to be bigger than any other operand.
75 return (a.compareTo(b) < 0) ? b : a;
94 } 76 }
95 77
96 /** 78 /**
97 * Returns the maximum of two numbers. If either argument is NaN returns NaN.
98 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are
99 * equal (int and doubles with the same mathematical value are equal) then
100 * it is unspecified which of the two arguments is returned.
101 */
102 num max(num a, num b) {
103 if (a is num) {
104 // TODO(floitsch): merge this if into the previous one, once dart2js
105 // correctly propagates types for logical ands.
106 if (b is num) {
107 if (a > b) return a;
108 if (a < b) return b;
109 if (b is double) {
110 // Special case for NaN and -0.0. If one argument is NaN return NaN.
111 // [max] must also distinguish between -0.0 and 0.0.
112 if (a is double) {
113 if (a == 0.0) {
114 // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN.
115 // The following returns 0.0 if either a or b is 0.0, and it
116 // returns NaN if b is NaN.
117 return a + b;
118 }
119 }
120 // Check for NaN.
121 if (b.isNaN()) return b;
122 return a;
123 }
124 // max(-0.0, 0) must return 0.
125 if (b == 0 && a.isNegative()) return b;
126 return a;
127 }
128 throw new IllegalArgumentException(b);
129 }
130 throw new IllegalArgumentException(a);
131 }
132
133 /**
134 * Returns the arc tangent of [a]/[b] with sign according to quadrant. 79 * Returns the arc tangent of [a]/[b] with sign according to quadrant.
135 */ 80 */
136 external double atan2(num a, num b); 81 external double atan2(num a, num b);
137 82
138 /** 83 /**
139 * If the [exponent] is an integer the result is of the same type as [x]. 84 * If the [exponent] is an integer the result is of the same type as [x].
140 * Otherwise it is a [double]. 85 * Otherwise it is a [double].
141 */ 86 */
142 external num pow(num x, num exponent); 87 external num pow(num x, num exponent);
143 88
144 external double sin(num x); 89 external double sin(num x);
145 external double cos(num x); 90 external double cos(num x);
146 external double tan(num x); 91 external double tan(num x);
147 external double acos(num x); 92 external double acos(num x);
148 external double asin(num x); 93 external double asin(num x);
149 external double atan(num x); 94 external double atan(num x);
150 external double sqrt(num x); 95 external double sqrt(num x);
151 external double exp(num x); 96 external double exp(num x);
152 external double log(num x); 97 external double log(num x);
OLDNEW
« no previous file with comments | « no previous file | corelib/unified/math/random.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698