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

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

Issue 10389150: - Add a math library. Currently it mostly matches the Math class in dart:core. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | lib/math/math.dart » ('j') | tests/lib/lib.status » ('J')
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
49 * an [int]. Throws a [BadNumberFormatException] if [str]
50 * cannot be parsed as an [int].
51 */
52 int parseInt(String str) => MathNatives.parseInt(str);
53
54 /**
55 * Parses a [String] representation of a [double], and returns
56 * a [double]. Throws a [BadNumberFormatException] if [str] cannot
57 * be parsed as a [double].
58 */
59 double parseDouble(String str) => MathNatives.parseDouble(str);
60
61 num min(num a, num b) {
62 int c = a.compareTo(b);
63 if (c == 0) return a;
64 if (c < 0) {
65 if ((b is double) && b.isNaN()) return b;
66 return a;
67 }
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;
76 }
77
78 /**
79 * Returns the arc tangent of [a]/[b] with sign according to quadrant.
80 */
81 double atan2(num a, num b) => MathNatives.atan2(a, b);
82
83 /**
84 * If the [exponent] is an integer the result is of the same type as [x].
85 * Otherwise it is a [double].
86 */
87 num pow(num x, num exponent) => MathNatives.pow(x, exponent);
88
89 double sin(num x) => MathNatives.sin(x);
90 double cos(num x) => MathNatives.cos(x);
91 double tan(num x) => MathNatives.tan(x);
92 double acos(num x) => MathNatives.acos(x);
93 double asin(num x) => MathNatives.asin(x);
94 double atan(num x) => MathNatives.atan(x);
95 double sqrt(num x) => MathNatives.sqrt(x);
96 double exp(num x) => MathNatives.exp(x);
97 double log(num x) => MathNatives.log(x);
OLDNEW
« no previous file with comments | « no previous file | lib/math/math.dart » ('j') | tests/lib/lib.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698