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

Side by Side Diff: compiler/lib/implementation/number.dart

Issue 9702034: Removes dartc reliance on its own libraries, now can be targeted at any implementation's libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: junit tests fixed Created 8 years, 9 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 | « compiler/lib/implementation/math_natives.js ('k') | compiler/lib/implementation/number.js » ('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 class NumberImplementation implements int, double native "Number" {
6
7 NumberImplementation operator +(NumberImplementation other) native;
8 NumberImplementation operator -(NumberImplementation other) native;
9 NumberImplementation operator *(NumberImplementation other) native;
10 NumberImplementation operator /(NumberImplementation other) native;
11 NumberImplementation operator ~/(NumberImplementation other) native;
12 NumberImplementation operator %(NumberImplementation shiftAmount) native;
13 NumberImplementation operator negate() native;
14
15 int operator |(int other) native;
16 int operator &(int other) native;
17 int operator ^(int other) native;
18 int operator <<(int shiftAmount) native;
19 int operator >>(int shiftAmount) native;
20 int operator ~() native;
21
22 bool operator ==(NumberImplementation other) native;
23 bool operator <(NumberImplementation other) native;
24 bool operator <=(NumberImplementation other) native;
25 bool operator >(NumberImplementation other) native;
26 bool operator >=(NumberImplementation other) native;
27
28 NumberImplementation remainder(num other) native;
29 NumberImplementation abs() native;
30 NumberImplementation round() native;
31 NumberImplementation floor() native;
32 NumberImplementation ceil() native;
33 NumberImplementation truncate() native;
34
35 // CompareTo has to give a complete order, including -0/+0, NaN and
36 // Infinities.
37 // Order is: -Inf < .. < -0.0 < 0.0 .. < +inf < NaN.
38 NumberImplementation compareTo(NumberImplementation other) {
39 // Don't use the 'this' object (which is a JS Number object), but get the
40 // primitive JS number by invoking toDouble().
41 num thisValue = toDouble();
42 // Remember that NaN return false for any comparison.
43 if (thisValue < other) {
44 return -1;
45 } else if (thisValue > other) {
46 return 1;
47 } else if (thisValue == other) {
48 if (thisValue == 0) {
49 bool thisIsNegative = isNegative();
50 bool otherIsNegative = other.isNegative();
51 if (thisIsNegative == otherIsNegative) return 0;
52 if (thisIsNegative) return -1;
53 return 1;
54 }
55 return 0;
56 } else if (isNaN()) {
57 if (other.isNaN()) {
58 return 0;
59 }
60 return 1;
61 } else {
62 return -1;
63 }
64 }
65
66 bool isNegative() native;
67 bool isEven() native;
68 bool isOdd() native;
69 bool isNaN() native;
70 bool isInfinite() native;
71
72 int toInt() {
73 if (isNaN()) throw new BadNumberFormatException("NaN");
74 if (isInfinite()) throw new BadNumberFormatException("Infinity");
75 NumberImplementation truncated = truncate();
76 // If truncated is -0.0 return +0. The test will also trigger for positive
77 // 0s but that's not a problem.
78 if (truncated == -0.0) return 0;
79 return truncated;
80 }
81
82 NumberImplementation toDouble() native;
83 String toString() native;
84 String toStringAsFixed(int fractionDigits) native;
85 String toStringAsExponential(int fractionDigits) native;
86 String toStringAsPrecision(int precision) native;
87 String toRadixString(int radix) native;
88
89 int hashCode() native;
90 get dynamic() { return toDouble(); }
91 }
92
93 class _NumberJsUtil {
94 static void _throwIllegalArgumentException(var argument) native {
95 throw new IllegalArgumentException([argument]);
96 }
97 }
OLDNEW
« no previous file with comments | « compiler/lib/implementation/math_natives.js ('k') | compiler/lib/implementation/number.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698