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

Unified Diff: lib/double.dart

Issue 8273001: Fix issue 100: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/double.dart
===================================================================
--- lib/double.dart (revision 394)
+++ lib/double.dart (working copy)
@@ -12,38 +12,47 @@
return 0;
}
}
+
+ // Verified double conversion.
+ static double _checkedToDouble(num value) {
+ if (value is !num) {
+ throw const IllegalArgumentException("num value expected");
+ }
+ return value.toDouble();
+ }
+
double operator +(num other) {
- return add_(other.toDouble());
+ return add_(_checkedToDouble(other));
}
double add_(double other) native "Double_add";
double operator -(num other) {
- return sub_(other.toDouble());
+ return sub_(_checkedToDouble(other));
}
double sub_(double other) native "Double_sub";
double operator *(num other) {
- return mul_(other.toDouble());
+ return mul_(_checkedToDouble(other));
}
double mul_(double other) native "Double_mul";
double operator ~/(num other) {
- return trunc_div_(other.toDouble());
+ return trunc_div_(_checkedToDouble(other));
}
double trunc_div_(double other) native "Double_trunc_div";
double operator /(num other) {
- return div_(other.toDouble());
+ return div_(_checkedToDouble(other));
}
double div_(double other) native "Double_div";
double operator %(num other) {
- return modulo_(other.toDouble());
+ return modulo_(_checkedToDouble(other));
}
double modulo_(double other) native "Double_modulo";
double remainder(num other) {
- return remainder_(other.toDouble());
+ return remainder_(_checkedToDouble(other));
}
double remainder_(double other) native "Double_remainder";
@@ -52,7 +61,7 @@
}
bool operator ==(other) {
if (!(other is num)) return false;
- return equal_(other.toDouble());
+ return equal_(_checkedToDouble(other));
}
bool equal_(double other)native "Double_equal";
bool equalToInteger(int other) native "Double_equalToInteger";
@@ -60,7 +69,7 @@
return other > this;
}
bool operator >(num other) {
- return greaterThan_(other.toDouble());
+ return greaterThan_(_checkedToDouble(other));
}
bool greaterThan_(double other) native "Double_greaterThan";
bool operator >=(num other) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698