@@ -36,12 +36,13 @@ import scala.language.implicitConversions"""
3636 }
3737
3838 def isInteger : Boolean = isIntegerType(this )
39+
3940 def unaryOps = {
4041 val ops = List (
4142 Op (" +" , " /** Returns this value, unmodified. */" ),
4243 Op (" -" , " /** Returns the negation of this value. */" ))
4344
44- if (isInteger)
45+ if (isInteger)
4546 Op (" ~" , " /**\n " +
4647 " * Returns the bitwise negation of this value.\n " +
4748 " * @example {{{\n " +
@@ -135,16 +136,19 @@ import scala.language.implicitConversions"""
135136 Op (" /" , " /** Returns the quotient of this value and `x`. */" ),
136137 Op (" %" , " /** Returns the remainder of the division of this value by `x`. */" ))
137138
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:
139140 // 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.
141143 // Given two numeric values v and w the operation type of v and w is the operation type
142144 // of their run-time types.
143145 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
148152 }
149153 }
150154
0 commit comments