+fn max_value() -> int {
+ ret min_value() - 1;
+}
+
+fn min_value() -> int {
+ ret (-1 << (sys::size_of::<int>() * 8u as int - 1)) as int;
+}
pure fn add(x: int, y: int) -> int { ret x + y; }
+/**
+ * Return the minimal value for an uint.
+ *
+ * This is always 0
+ */
pure fn min_value() -> uint { ret 0u; }
+/**
+ * Return the maximal value for an uint.
+ *
+ * This is 2^wordsize - 1
+ */
+pure fn max_value() -> uint {
+ ret 0u - 1u;
+}
+
fn add(x: uint, y: uint) -> uint { ret x + y; }
fn sub(x: uint, y: uint) -> uint { ret x - y; }
assert (int::pow(-3, 3u) == -27);
assert (int::pow(4, 9u) == 262144);
}
+
+#[test]
+fn test_overflows() {
+ assert (int::max_value() > 0);
+ assert (int::min_value() <= 0);
+ assert (int::min_value() + int::max_value() + 1 == 0);
+}
\ No newline at end of file
assert (uint::next_power_of_two(38u) == 64u);
assert (uint::next_power_of_two(39u) == 64u);
}
+
+#[test]
+fn test_overflows() {
+ assert (uint::max_value() > 0u);
+ assert (uint::min_value() <= 0u);
+ assert (uint::min_value() + uint::max_value() + 1u == 0u);
+}
\ No newline at end of file