| OLD | NEW |
| 1 // Copyright (c) 2011, 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 class _Double implements double { | 5 class _Double implements double { |
| 6 factory _Double.fromInteger(int value) | 6 factory _Double.fromInteger(int value) |
| 7 native "Double_doubleFromInteger"; | 7 native "Double_doubleFromInteger"; |
| 8 int hashCode() { | 8 int hashCode() { |
| 9 try { | 9 try { |
| 10 return toInt(); | 10 return toInt(); |
| 11 } on FormatException catch (e) { | 11 } on FormatException catch (e) { |
| 12 return 0; | 12 return 0; |
| 13 } | 13 } |
| 14 } | 14 } |
| 15 double operator +(num other) { | 15 double operator +(num other) { |
| 16 return add_(other.toDouble()); | 16 return _add(other.toDouble()); |
| 17 } | 17 } |
| 18 double add_(double other) native "Double_add"; | 18 double _add(double other) native "Double_add"; |
| 19 | 19 |
| 20 double operator -(num other) { | 20 double operator -(num other) { |
| 21 return sub_(other.toDouble()); | 21 return _sub(other.toDouble()); |
| 22 } | 22 } |
| 23 double sub_(double other) native "Double_sub"; | 23 double _sub(double other) native "Double_sub"; |
| 24 | 24 |
| 25 double operator *(num other) { | 25 double operator *(num other) { |
| 26 return mul_(other.toDouble()); | 26 return _mul(other.toDouble()); |
| 27 } | 27 } |
| 28 double mul_(double other) native "Double_mul"; | 28 double _mul(double other) native "Double_mul"; |
| 29 | 29 |
| 30 double operator ~/(num other) { | 30 double operator ~/(num other) { |
| 31 return trunc_div_(other.toDouble()); | 31 return _trunc_div(other.toDouble()); |
| 32 } | 32 } |
| 33 double trunc_div_(double other) native "Double_trunc_div"; | 33 double _trunc_div(double other) native "Double_trunc_div"; |
| 34 | 34 |
| 35 double operator /(num other) { | 35 double operator /(num other) { |
| 36 return div_(other.toDouble()); | 36 return _div(other.toDouble()); |
| 37 } | 37 } |
| 38 double div_(double other) native "Double_div"; | 38 double _div(double other) native "Double_div"; |
| 39 | 39 |
| 40 double operator %(num other) { | 40 double operator %(num other) { |
| 41 return modulo_(other.toDouble()); | 41 return _modulo(other.toDouble()); |
| 42 } | 42 } |
| 43 double modulo_(double other) native "Double_modulo"; | 43 double _modulo(double other) native "Double_modulo"; |
| 44 | 44 |
| 45 double remainder(num other) { | 45 double remainder(num other) { |
| 46 return remainder_(other.toDouble()); | 46 return _remainder(other.toDouble()); |
| 47 } | 47 } |
| 48 double remainder_(double other) native "Double_remainder"; | 48 double _remainder(double other) native "Double_remainder"; |
| 49 | |
| 50 double operator -() { | 49 double operator -() { |
| 51 if (this == 0.0) { | 50 if (this == 0.0) { |
| 52 // -0.0 is canonicalized by the VM's parser, therefore no cycles. | 51 // -0.0 is canonicalized by the VM's parser, therefore no cycles. |
| 53 return isNegative() ? 0.0 : -0.0; | 52 return isNegative() ? 0.0 : -0.0; |
| 54 } | 53 } |
| 55 return 0.0 - this; | 54 return 0.0 - this; |
| 56 } | 55 } |
| 57 bool operator ==(other) { | 56 bool operator ==(other) { |
| 58 if (!(other is num)) return false; | 57 if (!(other is num)) return false; |
| 59 return equal_(other.toDouble()); | 58 return _equal(other.toDouble()); |
| 60 } | 59 } |
| 61 bool equal_(double other)native "Double_equal"; | 60 bool _equal(double other)native "Double_equal"; |
| 62 bool equalToInteger(int other) native "Double_equalToInteger"; | 61 bool _equalToInteger(int other) native "Double_equalToInteger"; |
| 63 bool operator <(num other) { | 62 bool operator <(num other) { |
| 64 return other > this; | 63 return other > this; |
| 65 } | 64 } |
| 66 bool operator >(num other) { | 65 bool operator >(num other) { |
| 67 return greaterThan_(other.toDouble()); | 66 return _greaterThan(other.toDouble()); |
| 68 } | 67 } |
| 69 bool greaterThan_(double other) native "Double_greaterThan"; | 68 bool _greaterThan(double other) native "Double_greaterThan"; |
| 70 bool operator >=(num other) { | 69 bool operator >=(num other) { |
| 71 return (this == other) || (this > other); | 70 return (this == other) || (this > other); |
| 72 } | 71 } |
| 73 bool operator <=(num other) { | 72 bool operator <=(num other) { |
| 74 return (this == other) || (this < other); | 73 return (this == other) || (this < other); |
| 75 } | 74 } |
| 76 double addFromInteger(int other) { | 75 double _addFromInteger(int other) { |
| 77 return new _Double.fromInteger(other) + this; | 76 return new _Double.fromInteger(other) + this; |
| 78 } | 77 } |
| 79 double subFromInteger(int other) { | 78 double _subFromInteger(int other) { |
| 80 return new _Double.fromInteger(other) - this; | 79 return new _Double.fromInteger(other) - this; |
| 81 } | 80 } |
| 82 double mulFromInteger(int other) { | 81 double _mulFromInteger(int other) { |
| 83 return new _Double.fromInteger(other) * this; | 82 return new _Double.fromInteger(other) * this; |
| 84 } | 83 } |
| 85 double truncDivFromInteger(int other) { | 84 double _truncDivFromInteger(int other) { |
| 86 return new _Double.fromInteger(other) ~/ this; | 85 return new _Double.fromInteger(other) ~/ this; |
| 87 } | 86 } |
| 88 double moduloFromInteger(int other) { | 87 double _moduloFromInteger(int other) { |
| 89 return new _Double.fromInteger(other) % this; | 88 return new _Double.fromInteger(other) % this; |
| 90 } | 89 } |
| 91 double remainderFromInteger(int other) { | 90 double _remainderFromInteger(int other) { |
| 92 return new _Double.fromInteger(other).remainder(this); | 91 return new _Double.fromInteger(other).remainder(this); |
| 93 } | 92 } |
| 94 | 93 bool _greaterThanFromInteger(int other) |
| 95 bool greaterThanFromInteger(int other) native "Double_greaterThanFromInteger"; | 94 native "Double_greaterThanFromInteger"; |
| 96 | 95 |
| 97 bool isNegative() native "Double_isNegative"; | 96 bool isNegative() native "Double_isNegative"; |
| 98 bool isInfinite() native "Double_isInfinite"; | 97 bool isInfinite() native "Double_isInfinite"; |
| 99 bool isNaN() native "Double_isNaN"; | 98 bool isNaN() native "Double_isNaN"; |
| 100 | 99 |
| 101 double abs() { | 100 double abs() { |
| 102 // Handle negative 0.0. | 101 // Handle negative 0.0. |
| 103 if (this == 0.0) return 0.0; | 102 if (this == 0.0) return 0.0; |
| 104 return this < 0.0 ? -this : this; | 103 return this < 0.0 ? -this : this; |
| 105 } | 104 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return EQUAL; | 221 return EQUAL; |
| 223 } | 222 } |
| 224 } else if (isNaN()) { | 223 } else if (isNaN()) { |
| 225 return other.isNaN() ? EQUAL : GREATER; | 224 return other.isNaN() ? EQUAL : GREATER; |
| 226 } else { | 225 } else { |
| 227 // Other is NaN. | 226 // Other is NaN. |
| 228 return LESS; | 227 return LESS; |
| 229 } | 228 } |
| 230 } | 229 } |
| 231 } | 230 } |
| OLD | NEW |