|
|
@@ -286,12 +286,12 @@ Disadvantages:
|
|
|
expectations, for example in some important bit-manipulation cases.
|
|
|
- Give integer types a range of values rather than simply a bit-width. For
|
|
|
example, we can say that negation on `i32` produces a type that can
|
|
|
- represent [-2<sup>31</sup>+1, 2<sup>31</sup>], which still fits in 32
|
|
|
- bits. However, this would add significant complexity to the type system,
|
|
|
- and with this approach, division would still increase the bit width: for
|
|
|
- example, `a / b`, where `a` and `b` are `iN`s, has 2<sup>`N`</sup>+1
|
|
|
- distinct possible values. This is especially surprising because integer
|
|
|
- division is usually expected to make a number smaller!
|
|
|
+ represent [-2<sup>31</sup>+1, 2<sup>31</sup>], which still fits in 32 bits.
|
|
|
+ However, this would add significant complexity to the type system, and with
|
|
|
+ this approach, division would still increase the bit width: for example,
|
|
|
+ `a / b`, where `a` and `b` are `iN`s, has 2<sup>`N`</sup>+1 distinct possible
|
|
|
+ values. This is especially surprising because integer division is usually
|
|
|
+ expected to make a number smaller!
|
|
|
- Refactoring code becomes more challenging, as the appropriate intermediate
|
|
|
type must be determined. Mitigating this, the type system would inform the
|
|
|
programmer when they make a mistake.
|
|
|
@@ -379,9 +379,9 @@ cases are:
|
|
|
difference of such unsigned quantities, and it's generally preferable for
|
|
|
such subtractions to produce a negative result rather than a subtle bug.
|
|
|
Moreover, while a restriction to non-negative values is common, supporting
|
|
|
- only the case of a range restriction to [0, 2<sup>N</sup>-1], but not any
|
|
|
- other range, does not do a good job of addressing the general desire to
|
|
|
- capture intent and to make invalid states unrepresentable.
|
|
|
+ only the case of a range restriction to [0, 2<sup>N</sup>-1], but not any other
|
|
|
+ range, does not do a good job of addressing the general desire to capture intent
|
|
|
+ and to make invalid states unrepresentable.
|
|
|
- Ability to reduce storage size. Spending a sign bit every time a number is
|
|
|
stored, even when it's known to be non-negative is wasteful. This is an
|
|
|
important concern, and one we should address, but it's thought to be better
|