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

Unified Diff: sdk/lib/core/num.dart

Issue 12317107: ceil/floor/truncate/round return integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload due to error3 Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/core/int.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/num.dart
diff --git a/sdk/lib/core/num.dart b/sdk/lib/core/num.dart
index 1276868338e85a6efd9ac72f4d2796f7eb8d7805..3551fc6d19ab49721678d52faed49ae6688c8368 100644
--- a/sdk/lib/core/num.dart
+++ b/sdk/lib/core/num.dart
@@ -26,11 +26,12 @@ abstract class num implements Comparable<num> {
/**
* Truncating division operator.
*
- * The result of the truncating division [:a ~/ b:] is equivalent to
- * [:(a / b).truncate().toInt():].
+ * If either operand is a [double] then the result of the truncating division
+ * [:a ~/ b:] is equivalent to [:(a / b).truncate().toInt():].
+ *
+ * If both operands are [int]s then [:a ~/ b:] performs the truncating
+ * integer division.
*/
- // TODO(floitsch): this is currently not true: bignum1 / bignum2 will return
- // NaN, whereas bignum1 ~/ bignum2 will give the correct result.
int operator ~/(num other);
/** Negate operator. */
@@ -60,25 +61,69 @@ abstract class num implements Comparable<num> {
/** Returns the absolute value of this [num]. */
num abs();
- /** Returns the greatest integer value no greater than this [num]. */
- num floor();
+ /**
+ * Returns the integer closest to `this`.
+ *
+ * Rounds away from zero when there is no closest integer:
+ * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
+ *
+ * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
+ */
+ int round();
+
+ /**
+ * Returns the greatest integer no greater than `this`.
+ *
+ * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
+ */
+ int floor();
+
+ /**
+ * Returns the least integer no smaller than `this`.
+ *
+ * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
+ */
+ int ceil();
- /** Returns the least integer value that is no smaller than this [num]. */
- num ceil();
+ /**
+ * Returns the integer obtained by discarding any fractional
+ * digits from `this`.
+ *
+ * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
+ */
+ int truncate();
/**
- * Returns the integer value closest to this [num].
+ * Returns the integer value closest to `this`.
*
* Rounds away from zero when there is no closest integer:
* [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
+ *
+ * The result is a double.
+ */
+ double roundToDouble();
+
+ /**
+ * Returns the greatest integer value no greater than `this`.
+ *
+ * The result is a double.
*/
- num round();
+ double floorToDouble();
/**
- * Returns the integer value obtained by discarding any fractional
- * digits from this [num].
+ * Returns the least integer value no smaller than `this`.
+ *
+ * The result is a double.
+ */
+ double ceilToDouble();
+
+ /**
+ * Returns the integer obtained by discarding any fractional
+ * digits from `this`.
+ *
+ * The result is a double.
*/
- num truncate();
+ double truncateToDouble();
/**
* Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison
« no previous file with comments | « sdk/lib/core/int.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698