@@ -36,12 +36,13 @@ import scala.language.implicitConversions"""
36
36
}
37
37
38
38
def isInteger : Boolean = isIntegerType(this )
39
+
39
40
def unaryOps = {
40
41
val ops = List (
41
42
Op (" +" , " /** Returns this value, unmodified. */" ),
42
43
Op (" -" , " /** Returns the negation of this value. */" ))
43
44
44
- if (isInteger)
45
+ if (isInteger)
45
46
Op (" ~" , " /**\n " +
46
47
" * Returns the bitwise negation of this value.\n " +
47
48
" * @example {{{\n " +
@@ -135,16 +136,19 @@ import scala.language.implicitConversions"""
135
136
Op (" /" , " /** Returns the quotient of this value and `x`. */" ),
136
137
Op (" %" , " /** Returns the remainder of the division of this value by `x`. */" ))
137
138
138
- // Given two numeric value types S and T , the operation type of S and T is defined as follows:
139
+ // Given two numeric value types S and T, the operation type of S and T is defined as follows:
139
140
// If both S and T are subrange types then the operation type of S and T is Int.
140
- // Otherwise the operation type of S and T is the larger of the two types wrt ranking.
141
+ // Otherwise the operation type of S and T is the larger of the two types w.r.t. the ordering
142
+ // of numeric types defined in `fullTypes` below.
141
143
// Given two numeric values v and w the operation type of v and w is the operation type
142
144
// of their run-time types.
143
145
def opType (that : AnyValNum ): AnyValNum = {
144
- val rank = IndexedSeq (I , L , F , D )
145
- (rank indexOf this , rank indexOf that) match {
146
- case (- 1 , - 1 ) => I
147
- case (r1, r2) => rank apply (r1 max r2)
146
+ val fullTypes = IndexedSeq (I , L , F , D )
147
+ (fullTypes.indexOf(this ), fullTypes.indexOf(that)) match {
148
+ case (- 1 , - 1 ) => I // both are subrange types
149
+ case (- 1 , _) => that // one is subrange
150
+ case (_, - 1 ) => this
151
+ case (r1, r2) => fullTypes(r1.max(r2)) // use the larger type
148
152
}
149
153
}
150
154
0 commit comments