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

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

Issue 10831324: Cleanup of math sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Another attempt 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 | corelib/unified/math/math.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // A part of the dart:math library.
6
7 /**
8 * Base of the natural logarithms.
9 */
10 final double E = 2.718281828459045;
11
12 /**
13 * Natural logarithm of 10.
14 */
15 final double LN10 = 2.302585092994046;
16
17 /**
18 * Natural logarithm of 2.
19 */
20 final double LN2 = 0.6931471805599453;
21
22 /**
23 * Base-2 logarithm of E.
24 */
25 final double LOG2E = 1.4426950408889634;
26
27 /**
28 * Base-10 logarithm of E.
29 */
30 final double LOG10E = 0.4342944819032518;
31
32 /**
33 * The PI constant.
34 */
35 final double PI = 3.1415926535897932;
36
37 /**
38 * Square root of 1/2.
39 */
40 final double SQRT1_2 = 0.7071067811865476;
41
42 /**
43 * Square root of 2.
44 */
45 final double SQRT2 = 1.4142135623730951;
46
47 /**
48 * Parses a [String] representation of an [int], and returns an [int]. Throws a
49 * [FormatException] if [str] cannot be parsed as an [int].
50 */
51 external int parseInt(String str);
52
53 /**
54 * Parses a [String] representation of a [double], and returns a [double].
55 * Throws a [FormatException] if [str] cannot be parsed as a [double].
56 */
57 external double parseDouble(String str);
58
59 /**
60 * Returns the minimum of two numbers. If either argument is NaN returns NaN.
61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are
62 * equal (int and doubles with the same mathematical value are equal) then
63 * it is unspecified which of the two arguments is returned.
64 */
65 num min(num a, num b) {
66 if (a is num) {
67 // TODO(floitsch): merge this if into the previous one, once dart2js
68 // correctly propagates types for logical ands.
69 if (b is num) {
70 if (a > b) return b;
71 if (a < b) return a;
72 if (b is double) {
73 // Special case for NaN and -0.0. If one argument is NaN return NaN.
74 // [min] must also distinguish between -0.0 and 0.0.
75 if (a is double) {
76 if (a == 0.0) {
77 // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN.
78 // The following returns -0.0 if either a or b is -0.0, and it
79 // returns NaN if b is NaN.
80 return (a + b) * a * b;
81 }
82 }
83 // Check for NaN and b == -0.0.
84 if (a == 0 && b.isNegative() || b.isNaN()) return b;
85 return a;
86 }
87 return a;
88 }
89 throw new IllegalArgumentException(b);
90 }
91 throw new IllegalArgumentException(a);
92 }
93
94 /**
95 * Returns the maximum of two numbers. If either argument is NaN returns NaN.
96 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are
97 * equal (int and doubles with the same mathematical value are equal) then
98 * it is unspecified which of the two arguments is returned.
99 */
100 num max(num a, num b) {
101 if (a is num) {
102 // TODO(floitsch): merge this if into the previous one, once dart2js
103 // correctly propagates types for logical ands.
104 if (b is num) {
105 if (a > b) return a;
106 if (a < b) return b;
107 if (b is double) {
108 // Special case for NaN and -0.0. If one argument is NaN return NaN.
109 // [max] must also distinguish between -0.0 and 0.0.
110 if (a is double) {
111 if (a == 0.0) {
112 // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN.
113 // The following returns 0.0 if either a or b is 0.0, and it
114 // returns NaN if b is NaN.
115 return a + b;
116 }
117 }
118 // Check for NaN.
119 if (b.isNaN()) return b;
120 return a;
121 }
122 // max(-0.0, 0) must return 0.
123 if (b == 0 && a.isNegative()) return b;
124 return a;
125 }
126 throw new IllegalArgumentException(b);
127 }
128 throw new IllegalArgumentException(a);
129 }
130
131 /**
132 * Returns the arc tangent of [a]/[b] with sign according to quadrant.
133 */
134 external double atan2(num a, num b);
135
136 /**
137 * If the [exponent] is an integer the result is of the same type as [x].
138 * Otherwise it is a [double].
139 */
140 external num pow(num x, num exponent);
141
142 // TODO(4512): Add documentation.
143 external double sin(num x);
144 external double cos(num x);
145 external double tan(num x);
146 external double acos(num x);
147 external double asin(num x);
148 external double atan(num x);
149 external double sqrt(num x);
150 external double exp(num x);
151 external double log(num x);
OLDNEW
« no previous file with comments | « no previous file | corelib/unified/math/math.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698