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

Side by Side Diff: lib/math/base.dart

Issue 10879032: Add documentation to the trigonometric functions in the math library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | no next file » | 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 *
10 * Typically written as "e".
9 */ 11 */
10 final double E = 2.718281828459045; 12 final double E = 2.718281828459045;
11 13
12 /** 14 /**
13 * Natural logarithm of 10. 15 * Natural logarithm of 10.
14 */ 16 */
15 final double LN10 = 2.302585092994046; 17 final double LN10 = 2.302585092994046;
16 18
17 /** 19 /**
18 * Natural logarithm of 2. 20 * Natural logarithm of 2.
19 */ 21 */
20 final double LN2 = 0.6931471805599453; 22 final double LN2 = 0.6931471805599453;
21 23
22 /** 24 /**
23 * Base-2 logarithm of E. 25 * Base-2 logarithm of [E].
24 */ 26 */
25 final double LOG2E = 1.4426950408889634; 27 final double LOG2E = 1.4426950408889634;
26 28
27 /** 29 /**
28 * Base-10 logarithm of E. 30 * Base-10 logarithm of [E].
29 */ 31 */
30 final double LOG10E = 0.4342944819032518; 32 final double LOG10E = 0.4342944819032518;
31 33
32 /** 34 /**
33 * The PI constant. 35 * The PI constant.
34 */ 36 */
35 final double PI = 3.1415926535897932; 37 final double PI = 3.1415926535897932;
36 38
37 /** 39 /**
38 * Square root of 1/2. 40 * Square root of 1/2.
39 */ 41 */
40 final double SQRT1_2 = 0.7071067811865476; 42 final double SQRT1_2 = 0.7071067811865476;
41 43
42 /** 44 /**
43 * Square root of 2. 45 * Square root of 2.
44 */ 46 */
45 final double SQRT2 = 1.4142135623730951; 47 final double SQRT2 = 1.4142135623730951;
46 48
47 /** 49 /**
48 * Parses a [String] representation of an [int], and returns an [int]. Throws a 50 * Parses a [String] representation of an [int], and returns an [int].
49 * [FormatException] if [str] cannot be parsed as an [int]. 51 *
52 * Throws a [FormatException] if [str] cannot be parsed as an [int].
50 */ 53 */
51 external int parseInt(String str); 54 external int parseInt(String str);
52 55
53 /** 56 /**
54 * Parses a [String] representation of a [double], and returns a [double]. 57 * Parses a [String] representation of a [double], and returns a [double].
58 *
55 * Throws a [FormatException] if [str] cannot be parsed as a [double]. 59 * Throws a [FormatException] if [str] cannot be parsed as a [double].
56 */ 60 */
57 external double parseDouble(String str); 61 external double parseDouble(String str);
58 62
59 /** 63 /**
60 * Returns the minimum of two numbers. If either argument is NaN returns NaN. 64 * Returns the lesser of two numbers.
61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are 65 *
62 * equal (int and doubles with the same mathematical value are equal) then 66 * Returns NaN if either argument is NaN.
63 * it is unspecified which of the two arguments is returned. 67 * The lesser of [:-0.0:] and [:0.0:] is [:-0.0:].
68 * If the arguments are otherwise equal (including int and doubles with the
69 * same mathematical value) then it is unspecified which of the two arguments
70 * is returned.
64 */ 71 */
65 num min(num a, num b) { 72 num min(num a, num b) {
66 if (a is num) { 73 if (a is num) {
67 // TODO(floitsch): merge this if into the previous one, once dart2js 74 // TODO(floitsch): merge this if into the previous one, once dart2js
68 // correctly propagates types for logical ands. 75 // correctly propagates types for logical ands.
69 if (b is num) { 76 if (b is num) {
70 if (a > b) return b; 77 if (a > b) return b;
71 if (a < b) return a; 78 if (a < b) return a;
72 if (b is double) { 79 if (b is double) {
73 // Special case for NaN and -0.0. If one argument is NaN return NaN. 80 // Special case for NaN and -0.0. If one argument is NaN return NaN.
(...skipping 11 matching lines...) Expand all
85 return a; 92 return a;
86 } 93 }
87 return a; 94 return a;
88 } 95 }
89 throw new IllegalArgumentException(b); 96 throw new IllegalArgumentException(b);
90 } 97 }
91 throw new IllegalArgumentException(a); 98 throw new IllegalArgumentException(a);
92 } 99 }
93 100
94 /** 101 /**
95 * Returns the maximum of two numbers. If either argument is NaN returns NaN. 102 * Returns the larger of two numbers.
96 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are 103 *
97 * equal (int and doubles with the same mathematical value are equal) then 104 * Returns NaN if either argument is NaN.
98 * it is unspecified which of the two arguments is returned. 105 * The larger of [:-0.0:] and [:0.0:] is [:0.0:]. If the arguments are
106 * otherwise equal (including int and doubles with the same mathematical value)
107 * then it is unspecified which of the two arguments is returned.
99 */ 108 */
100 num max(num a, num b) { 109 num max(num a, num b) {
101 if (a is num) { 110 if (a is num) {
102 // TODO(floitsch): merge this if into the previous one, once dart2js 111 // TODO(floitsch): merge this if into the previous one, once dart2js
103 // correctly propagates types for logical ands. 112 // correctly propagates types for logical ands.
104 if (b is num) { 113 if (b is num) {
105 if (a > b) return a; 114 if (a > b) return a;
106 if (a < b) return b; 115 if (a < b) return b;
107 if (b is double) { 116 if (b is double) {
108 // Special case for NaN and -0.0. If one argument is NaN return NaN. 117 // Special case for NaN and -0.0. If one argument is NaN return NaN.
(...skipping 13 matching lines...) Expand all
122 // max(-0.0, 0) must return 0. 131 // max(-0.0, 0) must return 0.
123 if (b == 0 && a.isNegative()) return b; 132 if (b == 0 && a.isNegative()) return b;
124 return a; 133 return a;
125 } 134 }
126 throw new IllegalArgumentException(b); 135 throw new IllegalArgumentException(b);
127 } 136 }
128 throw new IllegalArgumentException(a); 137 throw new IllegalArgumentException(a);
129 } 138 }
130 139
131 /** 140 /**
132 * Returns the arc tangent of [a]/[b] with sign according to quadrant. 141 * A variant of [atan].
142 *
143 * Converts both arguments to doubles.
144 *
145 * Returns the angle between the positive x-axis and the vector ([b],[a]).
146 * The result, in radians, is in the range -PI..PI.
147 *
148 * If [b] is positive, this is the same as [:atan(b/a):].
149 *
150 * The result is negative when [a] is negative (including when [a] is the
151 * double -0.0).
152 *
153 * If [a] is equal to zero, the vector ([b],[a]) is considered parallel to
154 * the x-axis, even if [b] is also equal to zero. The sign of [b] determines
155 * the direction of the vector along the x-axis.
156 *
157 * Returns NaN if either argument is NaN.
133 */ 158 */
134 external double atan2(num a, num b); 159 external double atan2(num a, num b);
135 160
136 /** 161 /**
137 * If the [exponent] is an integer the result is of the same type as [x]. 162 * Returns [x] to the power of [exponent].
138 * Otherwise it is a [double]. 163 *
164 * If [x] is an [int] and [exponent] is a non-negative [int], the result is
165 * an [int], otherwise the result it is a [double].
166 *
167 * Notice that an [int] result cannot overflow, but a [double] result might
168 * be [double.INFINITY].
139 */ 169 */
140 external num pow(num x, num exponent); 170 external num pow(num x, num exponent);
141 171
142 // TODO(4512): Add documentation. 172 /**
173 * Converts [x] to a double and returns the sine of the value.
174 *
175 * If [x] is not a finite number, the result is NaN.
176 */
143 external double sin(num x); 177 external double sin(num x);
178
179 /**
180 * Converts [x] to a double and returns the cosine of the value.
181 *
182 * If [x] is not a finite number, the result is NaN.
183 */
144 external double cos(num x); 184 external double cos(num x);
185
186 /**
187 * Converts [x] to a double and returns the tangent of the value.
188 *
189 * The tangent function is equivalent to [:sin(x)/cos(x):] and may be
190 * infinite (positive or negative) when [:cos(x):] is equal to zero.
191 * If [x] is not a finite number, the result is NaN.
192 */
145 external double tan(num x); 193 external double tan(num x);
194
195 /**
196 * Converts [x] to a double and returns the arc cosine of the value.
197 *
198 * Returns a value in the range -PI..PI, or NaN if [x] is outside
199 * the range -1..1.
200 */
146 external double acos(num x); 201 external double acos(num x);
202
203 /**
204 * Converts [x] to a double and returns the arc sine of the value.
205 * Returns a value in the range -PI..PI, or NaN if [x] is outside
206 * the range -1..1.
207 */
147 external double asin(num x); 208 external double asin(num x);
209
210 /**
211 * Converts [x] to a dobule and returns the arc tangent of the vlaue.
212 * Returns a value in the range -PI/2..PI/2, or NaN if [x] is NaN.
213 */
148 external double atan(num x); 214 external double atan(num x);
215
216 /**
217 * Converts [x] to a double and returns the positive square root of the value.
218 *
219 * Returns -0.0 if [x] is -0.0, and NaN if [x] is otherwise negative or NaN.
220 */
149 external double sqrt(num x); 221 external double sqrt(num x);
222
223 /**
224 * Converts [x] to a double and returns the natural exponent, [E],
225 * to the power [x].
226 * Returns NaN if [x] is NaN.
227 */
150 external double exp(num x); 228 external double exp(num x);
229
230 /**
231 * Converts [x] to a double and returns the natural logarithm of the value.
232 * Returns negative infinity if [x] is equal to zero.
233 * Returns NaN if [x] is NaN or less than zero.
234 */
151 external double log(num x); 235 external double log(num x);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698