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

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, 4 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.
ahe 2012/08/23 10:11:56 How about adding something like: Also known as "e"
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
9 */ 9 */
10 final double E = 2.718281828459045; 10 final double E = 2.718281828459045;
11 11
12 /** 12 /**
13 * Natural logarithm of 10. 13 * Natural logarithm of 10.
14 */ 14 */
15 final double LN10 = 2.302585092994046; 15 final double LN10 = 2.302585092994046;
16 16
17 /** 17 /**
18 * Natural logarithm of 2. 18 * Natural logarithm of 2.
19 */ 19 */
20 final double LN2 = 0.6931471805599453; 20 final double LN2 = 0.6931471805599453;
21 21
22 /** 22 /**
23 * Base-2 logarithm of E. 23 * Base-2 logarithm of [E].
24 */ 24 */
25 final double LOG2E = 1.4426950408889634; 25 final double LOG2E = 1.4426950408889634;
26 26
27 /** 27 /**
28 * Base-10 logarithm of E. 28 * Base-10 logarithm of [E].
29 */ 29 */
30 final double LOG10E = 0.4342944819032518; 30 final double LOG10E = 0.4342944819032518;
31 31
32 /** 32 /**
33 * The PI constant. 33 * The PI constant.
34 */ 34 */
35 final double PI = 3.1415926535897932; 35 final double PI = 3.1415926535897932;
36 36
37 /** 37 /**
38 * Square root of 1/2. 38 * Square root of 1/2.
(...skipping 11 matching lines...) Expand all
50 */ 50 */
51 external int parseInt(String str); 51 external int parseInt(String str);
52 52
53 /** 53 /**
54 * Parses a [String] representation of a [double], and returns a [double]. 54 * Parses a [String] representation of a [double], and returns a [double].
55 * Throws a [FormatException] if [str] cannot be parsed as a [double]. 55 * Throws a [FormatException] if [str] cannot be parsed as a [double].
56 */ 56 */
57 external double parseDouble(String str); 57 external double parseDouble(String str);
58 58
59 /** 59 /**
60 * Returns the minimum of two numbers. If either argument is NaN returns NaN. 60 * Returns the lesser of two numbers. Returns NaN if either argument is NaN.
ahe 2012/08/23 10:44:36 General comment. If you start a new paragraph afte
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are 61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If the arguments are
62 * equal (int and doubles with the same mathematical value are equal) then 62 * equal (int and doubles with the same mathematical value are equal) then
63 * it is unspecified which of the two arguments is returned. 63 * it is unspecified which of the two arguments is returned.
64 */ 64 */
65 num min(num a, num b) { 65 num min(num a, num b) {
66 if (a is num) { 66 if (a is num) {
67 // TODO(floitsch): merge this if into the previous one, once dart2js 67 // TODO(floitsch): merge this if into the previous one, once dart2js
68 // correctly propagates types for logical ands. 68 // correctly propagates types for logical ands.
69 if (b is num) { 69 if (b is num) {
70 if (a > b) return b; 70 if (a > b) return b;
71 if (a < b) return a; 71 if (a < b) return a;
(...skipping 13 matching lines...) Expand all
85 return a; 85 return a;
86 } 86 }
87 return a; 87 return a;
88 } 88 }
89 throw new IllegalArgumentException(b); 89 throw new IllegalArgumentException(b);
90 } 90 }
91 throw new IllegalArgumentException(a); 91 throw new IllegalArgumentException(a);
92 } 92 }
93 93
94 /** 94 /**
95 * Returns the maximum of two numbers. If either argument is NaN returns NaN. 95 * Returns the larger of two numbers. Returns NaN if either argument is NaN.
96 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are 96 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If the arguments are
ahe 2012/08/23 10:11:56 maximum -> larger.
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
97 * equal (int and doubles with the same mathematical value are equal) then 97 * equal (int and doubles with the same mathematical value are equal) then
98 * it is unspecified which of the two arguments is returned. 98 * it is unspecified which of the two arguments is returned.
99 */ 99 */
100 num max(num a, num b) { 100 num max(num a, num b) {
101 if (a is num) { 101 if (a is num) {
102 // TODO(floitsch): merge this if into the previous one, once dart2js 102 // TODO(floitsch): merge this if into the previous one, once dart2js
103 // correctly propagates types for logical ands. 103 // correctly propagates types for logical ands.
104 if (b is num) { 104 if (b is num) {
105 if (a > b) return a; 105 if (a > b) return a;
106 if (a < b) return b; 106 if (a < b) return b;
(...skipping 15 matching lines...) Expand all
122 // max(-0.0, 0) must return 0. 122 // max(-0.0, 0) must return 0.
123 if (b == 0 && a.isNegative()) return b; 123 if (b == 0 && a.isNegative()) return b;
124 return a; 124 return a;
125 } 125 }
126 throw new IllegalArgumentException(b); 126 throw new IllegalArgumentException(b);
127 } 127 }
128 throw new IllegalArgumentException(a); 128 throw new IllegalArgumentException(a);
129 } 129 }
130 130
131 /** 131 /**
132 * Returns the arc tangent of [a]/[b] with sign according to quadrant. 132 * Returns the angle between the positive x-axis and the vector ([b],[a]).
ahe 2012/08/23 10:44:36 See if you can simplify the first sentence. For ex
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
133 * The result, in radians, is in the range -PI..PI. If [a] is positive, this
ahe 2012/08/23 10:44:36 How about one paragraph per case?
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
134 * is equivalent to [:atan(a/b):]. If [a] is negative, the result is negative
135 * (including when [a] is the double -0.0).
136 * If [a] is equal to zero, the vector ([b],[a]) is considered parallel to
137 * the x-axis, even if [b] is also equal to zero. The sign of [b] determines
138 * the direction of the vector along the x-axis.
139 * Returns [:NaN:] if either argument is [:NaN:].
133 */ 140 */
134 external double atan2(num a, num b); 141 external double atan2(num a, num b);
135 142
136 /** 143 /**
144 * Returns [x] to the power of [exponent].
ahe 2012/08/23 10:44:36 Add newline.
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
137 * If the [exponent] is an integer the result is of the same type as [x]. 145 * If the [exponent] is an integer the result is of the same type as [x].
ahe 2012/08/23 10:44:36 integer -> is of type int (and positive). 2.0 is
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Changed specification to return int if [x] is int
138 * Otherwise it is a [double]. 146 * Otherwise it is a [double].
ahe 2012/08/23 10:44:36 Perhaps add a note that int doesn't overflow, but
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
139 */ 147 */
140 external num pow(num x, num exponent); 148 external num pow(num x, num exponent);
141 149
142 // TODO(4512): Add documentation. 150 /**
151 * Converts [x] to a double and returns the sine of the value.
152 * If [x] is not a finite number, the result is [:NaN:].
153 */
143 external double sin(num x); 154 external double sin(num x);
155
156 /**
157 * Converts [x] to a double and returns the cosine of the value.
158 * If [x] is not a finite number, the result is [:NaN:].
159 */
144 external double cos(num x); 160 external double cos(num x);
161
162 /**
163 * Converts [x] to a double and returns the tangent of of the value.
164 * The tangent function is equivalent to [:sin(x)/cos(x):] and may be
165 * infinite (positive or negative) when [:cos(x):] is zero.
166 * If [x] is not a finite number, the result is [:NaN:].
167 */
145 external double tan(num x); 168 external double tan(num x);
169
170 /**
171 * Converts [x] to a double and returns the arc cosine of the value.
172 * Returns a value in the range -PI..PI, or [:NaN:] if [x] is outside
173 * the range -1..1.
ahe 2012/08/23 10:44:36 Check this.
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
174 */
146 external double acos(num x); 175 external double acos(num x);
176
177 /**
178 * Converts [x] to a double and returns the arc sine of the value.
179 * Returns a value in the range -PI..PI, or [:NaN:] if [x] is outside
180 * the range -1..1.
ahe 2012/08/23 10:44:36 Check this.
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Done.
181 */
147 external double asin(num x); 182 external double asin(num x);
183
184 /**
185 * Converts [x] to a dobule and returns the arc tangent of the vlaue.
186 * Returns a value in the range -PI..PI, or [:NaN:] if [x] is [:NaN:].
ahe 2012/08/23 10:44:36 Check this.
Lasse Reichstein Nielsen 2012/08/24 14:40:31 Changed to -PI/2..PI/2.
187 */
148 external double atan(num x); 188 external double atan(num x);
189
190 /**
191 * Converts [x] to a double and returns the square root of the value.
192 * Returns [:NaN:] if x is negative or [:NaN:].
ahe 2012/08/23 10:44:36 What about -0.0?
Lasse Reichstein Nielsen 2012/08/24 14:40:31 That returns -0.0, by IEEE-754 decree. Now documen
193 */
149 external double sqrt(num x); 194 external double sqrt(num x);
195
196 /**
197 * Converts [x] to a double and returns the natural exponent, [E],
198 * to the power [x].
199 * Returns [:NaN:] if [x] is [:NaN:].
200 */
150 external double exp(num x); 201 external double exp(num x);
202
203 /**
204 * Converts [x] to a double and returns the natural logarithm of the value.
205 * The result is [:NaN:] if [x] is [:NaN:], zero or negative.
206 */
151 external double log(num x); 207 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