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

Side by Side Diff: runtime/lib/math_patch.dart

Issue 14619027: Fix for issue 10534. Implement int.pow correctly. Note that int.pow is considerably slower than dou… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | « runtime/lib/integers.dart ('k') | tests/standalone/pow_test.dart » ('j') | 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 import "dart:typed_data"; 5 import "dart:typed_data";
6 6
7 // A VM patch of the dart:math library. 7 // A VM patch of the dart:math library.
8
9 // If [x] is an [int] and [exponent] is a non-negative [int], the result is
10 // an [int], otherwise the result is a [double].
8 patch num pow(num x, num exponent) { 11 patch num pow(num x, num exponent) {
9 if (exponent is int) { 12 if ((x is int) && (exponent is int) && (exponent >= 0)) {
10 return x.pow(exponent); 13 return x.pow(exponent);
11 } 14 }
12 // Double.pow will call exponent.toDouble(). 15 // Double.pow will call exponent.toDouble().
13 return x.toDouble().pow(exponent); 16 return x.toDouble().pow(exponent);
14 } 17 }
15 18
16 patch double atan2(num a, num b) => _atan2(a.toDouble(), b.toDouble()); 19 patch double atan2(num a, num b) => _atan2(a.toDouble(), b.toDouble());
17 patch double sin(num value) => _sin(value.toDouble()); 20 patch double sin(num value) => _sin(value.toDouble());
18 patch double cos(num value) => _cos(value.toDouble()); 21 patch double cos(num value) => _cos(value.toDouble());
19 patch double tan(num value) => _tan(value.toDouble()); 22 patch double tan(num value) => _tan(value.toDouble());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 115
113 static int _nextSeed() { 116 static int _nextSeed() {
114 if (_prng == null) { 117 if (_prng == null) {
115 // TODO(iposva): Use system to get a random seed. 118 // TODO(iposva): Use system to get a random seed.
116 _prng = new Random(new DateTime.now().millisecondsSinceEpoch); 119 _prng = new Random(new DateTime.now().millisecondsSinceEpoch);
117 } 120 }
118 // Trigger the PRNG once to change the internal state. 121 // Trigger the PRNG once to change the internal state.
119 return _prng._nextInt32(); 122 return _prng._nextInt32();
120 } 123 }
121 } 124 }
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | tests/standalone/pow_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698