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

Unified Diff: runtime/lib/integers.dart

Issue 2005723004: Fraction class prototype and test (not to be committed). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: work in progress Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/fraction.dart ('k') | runtime/lib/mirrors.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.dart
diff --git a/runtime/lib/integers.dart b/runtime/lib/integers.dart
index 0c5b11985bad5dd6648392883097aec8ee5f26cc..22188f9929c5332f7361a4a00b987b046f634471 100644
--- a/runtime/lib/integers.dart
+++ b/runtime/lib/integers.dart
@@ -92,13 +92,16 @@ abstract class _IntegerImplementation {
return other._greaterThanFromInteger(this);
}
bool operator >=(num other) {
- return (this == other) || (this > other);
+ return (this == other) || (this > other);
}
bool operator <=(num other) {
return (this == other) || (this < other);
}
bool _greaterThanFromInteger(int other)
native "Integer_greaterThanFromInteger";
+ bool _greaterThanFromFraction(fraction other) {
+ return other._numerator > (other._denominator * this);
+ }
bool operator ==(other) {
if (other is num) {
return other._equalToInteger(this);
@@ -106,6 +109,9 @@ abstract class _IntegerImplementation {
return false;
}
bool _equalToInteger(int other) native "Integer_equalToInteger";
+ bool _equalToFraction(fraction other) {
+ return (this * other._denominator) == other._numerator;
+ }
int abs() {
return this < 0 ? -this : this;
}
@@ -200,8 +206,11 @@ abstract class _IntegerImplementation {
int toInt() { return this; }
double toDouble() { return new _Double.fromInteger(this); }
+ fraction toFraction() { return new _Fraction.fromInteger(this); }
+ fraction toPercent() { return new _Fraction._percent(this*100); }
_Bigint _toBigint() { return new _Bigint._fromInt(this); }
- num _toBigintOrDouble() { return _toBigint(); }
+ num _toBigintIfInteger() { return _toBigint(); }
+ num _toDoubleOrFraction() { return new _Fraction.fromInteger(this); }
String toStringAsFixed(int fractionDigits) {
return this.toDouble().toStringAsFixed(fractionDigits);
« no previous file with comments | « runtime/lib/fraction.dart ('k') | runtime/lib/mirrors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698