Index: runtime/lib/double.dart |
diff --git a/runtime/lib/double.dart b/runtime/lib/double.dart |
index ade4b9317bcd75c3c5150c78372a803f8630516d..fd13bc42f1f4fca008a5269f3e2b57c7b6deb50a 100644 |
--- a/runtime/lib/double.dart |
+++ b/runtime/lib/double.dart |
@@ -6,6 +6,12 @@ class _Double implements double { |
factory _Double.fromInteger(int value) |
native "Double_doubleFromInteger"; |
+ factory _Double.fromFraction(fraction value) { |
+ return _DoubleFromFraction(value._numerator, value._denominator); |
+ } |
+ static _Double _DoubleFromFraction(int numerator, int denominator) |
+ native "Double_doubleFromFraction"; |
+ |
Type get runtimeType => double; |
// TODO: Make a stared static method for hashCode and _identityHashCode |
@@ -57,6 +63,7 @@ class _Double implements double { |
} |
bool _equal(double other) native "Double_equal"; |
bool _equalToInteger(int other) native "Double_equalToInteger"; |
+ bool _equalToFraction(fraction other) => _equal(other.toDouble()); |
bool operator <(num other) { |
return other > this; |
} |
@@ -91,6 +98,31 @@ class _Double implements double { |
bool _greaterThanFromInteger(int other) |
native "Double_greaterThanFromInteger"; |
+ double _addFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._add(this); |
+ } |
+ double _subFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._sub(this); |
+ } |
+ double _mulFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._mul(this); |
+ } |
+ double _divFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._div(this); |
+ } |
+ int _truncDivFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._trunc_div(this); |
+ } |
+ double _moduloFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._modulo(this); |
+ } |
+ double _remainderFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._remainder(this); |
+ } |
+ bool _greaterThanFromFraction(fraction other) { |
+ return new _Double.fromFraction(other)._greaterThan(this); |
+ } |
+ |
bool get isNegative native "Double_getIsNegative"; |
bool get isInfinite native "Double_getIsInfinite"; |
bool get isNaN native "Double_getIsNaN"; |
@@ -136,9 +168,21 @@ class _Double implements double { |
} |
int toInt() native "Double_toInt"; |
- num _toBigintOrDouble() { return this; } |
+ num _toBigintIfInteger() { return this; } |
+ num _toDoubleOrFraction() { return this; } |
double toDouble() { return this; } |
+ fraction toFraction() { |
+ var fract = new List(2); |
+ _DoubleToFraction(fract); |
+ return new _Fraction(fract[0], fract[1]); |
+ } |
+ void _DoubleToFraction(List fract) native "Double_toFraction"; |
+ |
+ fraction toPercent() { |
+ return new _Fraction((this*100).toInt(), 100); |
+ } |
+ |
static const int CACHE_SIZE_LOG2 = 3; |
static const int CACHE_LENGTH = 1 << (CACHE_SIZE_LOG2 + 1); |
static const int CACHE_MASK = CACHE_LENGTH - 1; |