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

Side by Side Diff: corelib/src/math.dart

Issue 10829459: Deprecate Math object in corelib in favor of dart:math library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. 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 | « corelib/src/implementation/date.dart ('k') | editor/util/debuggertest/pets.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) 2011, 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 // Dart core library.
6
7 /**
8 * *Note:* This class is **deprecated**, and will be removed soon.
9 * Please use the [dart:math] library instead.
10 */
11 class Math {
12 /**
13 * Base of the natural logarithms.
14 */
15 static final double E = 2.718281828459045;
16
17 /**
18 * Natural logarithm of 10.
19 */
20 static final double LN10 = 2.302585092994046;
21
22 /**
23 * Natural logarithm of 2.
24 */
25 static final double LN2 = 0.6931471805599453;
26
27 /**
28 * Base-2 logarithm of E.
29 */
30 static final double LOG2E = 1.4426950408889634;
31
32 /**
33 * Base-10 logarithm of E.
34 */
35 static final double LOG10E = 0.4342944819032518;
36
37 /**
38 * The PI constant.
39 */
40 static final double PI = 3.1415926535897932;
41
42 /**
43 * Square root of 1/2.
44 */
45 static final double SQRT1_2 = 0.7071067811865476;
46
47 /**
48 * Square root of 2.
49 */
50 static final double SQRT2 = 1.4142135623730951;
51
52 /**
53 * Parses a [String] representation of an [int], and returns an [int]. Throws
54 * a [FormatException] if [str] cannot be parsed as an [int].
55 */
56 static int parseInt(String str) => MathNatives.parseInt(str);
57
58 /**
59 * Parses a [String] representation of a [double], and returns a [double].
60 * Throws a [FormatException] if [str] cannot be parsed as a [double].
61 */
62 static double parseDouble(String str) => MathNatives.parseDouble(str);
63
64 /**
65 * Returns the minimum of two numbers. If either argument is NaN returns NaN.
66 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are
67 * equal (int and doubles with the same mathematical value are equal) then
68 * it is unspecified which of the two arguments is returned.
69 */
70 static num min(num a, num b) {
71 if (a is num) {
72 // TODO(floitsch): merge this if into the previous one, once dart2js
73 // correctly propagates types for logical ands.
74 if (b is num) {
75 if (a > b) return b;
76 if (a < b) return a;
77 if (b is double) {
78 // Special case for NaN and -0.0. If one argument is NaN return NaN.
79 // [min] must also distinguish between -0.0 and 0.0.
80 if (a is double) {
81 if (a == 0.0) {
82 // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN.
83 // The following returns -0.0 if either a or b is -0.0, and it
84 // returns NaN if b is NaN.
85 return (a + b) * a * b;
86 }
87 }
88 // Check for NaN and b == -0.0.
89 if (a == 0 && b.isNegative() || b.isNaN()) return b;
90 return a;
91 }
92 return a;
93 }
94 throw new IllegalArgumentException(b);
95 }
96 throw new IllegalArgumentException(a);
97 }
98
99 /**
100 * Returns the maximum of two numbers. If either argument is NaN returns NaN.
101 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are
102 * equal (int and doubles with the same mathematical value are equal) then
103 * it is unspecified which of the two arguments is returned.
104 */
105 static num max(num a, num b) {
106 if (a is num) {
107 // TODO(floitsch): merge this if into the previous one, once dart2js
108 // correctly propagates types for logical ands.
109 if (b is num) {
110 if (a > b) return a;
111 if (a < b) return b;
112 if (b is double) {
113 // Special case for NaN and -0.0. If one argument is NaN return NaN.
114 // [max] must also distinguish between -0.0 and 0.0.
115 if (a is double) {
116 if (a == 0.0) {
117 // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN.
118 // The following returns 0.0 if either a or b is 0.0, and it
119 // returns NaN if b is NaN.
120 return a + b;
121 }
122 }
123 // Check for NaN.
124 if (b.isNaN()) return b;
125 return a;
126 }
127 // max(-0.0, 0) must return 0.
128 if (b == 0 && a.isNegative()) return b;
129 return a;
130 }
131 throw new IllegalArgumentException(b);
132 }
133 throw new IllegalArgumentException(a);
134 }
135
136 /**
137 * Returns the arc tangent of [a]/[b] with sign according to quadrant.
138 */
139 static double atan2(num a, num b) => MathNatives.atan2(a, b);
140
141 /**
142 * If the [exponent] is an integer the result is of the same type as [x].
143 * Otherwise it is a [double].
144 */
145 static num pow(num x, num exponent) => MathNatives.pow(x, exponent);
146
147 /**
148 * Returns a random double greater than or equal to 0.0 and less
149 * than 1.0.
150 */
151 static double random() => MathNatives.random();
152
153 static double sin(num x) => MathNatives.sin(x);
154 static double cos(num x) => MathNatives.cos(x);
155 static double tan(num x) => MathNatives.tan(x);
156 static double acos(num x) => MathNatives.acos(x);
157 static double asin(num x) => MathNatives.asin(x);
158 static double atan(num x) => MathNatives.atan(x);
159 static double sqrt(num x) => MathNatives.sqrt(x);
160 static double exp(num x) => MathNatives.exp(x);
161 static double log(num x) => MathNatives.log(x);
162 }
OLDNEW
« no previous file with comments | « corelib/src/implementation/date.dart ('k') | editor/util/debuggertest/pets.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698