@@ -49,8 +49,86 @@ value class Dimen @PublishedApi internal constructor(val encodedValue: Long) {
49
49
else -> " NaN"
50
50
}
51
51
}
52
+
53
+ operator fun times (other : Double ): Dimen {
54
+ return Dimen (
55
+ when {
56
+ // DP case
57
+ encodedValue and NAN_MASK != NAN_MASK ->
58
+ doubleToRawLongBits(longBitsToDouble(encodedValue) * other)
59
+ // PX case
60
+ encodedValue and PX_FLAG == PX_FLAG ->
61
+ encodePxInt(((encodedValue and PAYLOAD_MASK ).toInt() * other).toInt())
62
+ // SP case
63
+ encodedValue and SP_FLAG == SP_FLAG ->
64
+ encodeSpFloat(
65
+ (intBitsToFloat((encodedValue and PAYLOAD_MASK ).toInt()) * other).toFloat())
66
+ else -> doubleToRawLongBits(Double .NaN )
67
+ })
68
+ }
69
+
70
+ operator fun times (other : Float ): Dimen {
71
+ return Dimen (
72
+ when {
73
+ // DP case
74
+ encodedValue and NAN_MASK != NAN_MASK ->
75
+ doubleToRawLongBits(longBitsToDouble(encodedValue) * other)
76
+ // PX case
77
+ encodedValue and PX_FLAG == PX_FLAG ->
78
+ encodePxInt(((encodedValue and PAYLOAD_MASK ).toInt() * other).toInt())
79
+ // SP case
80
+ encodedValue and SP_FLAG == SP_FLAG ->
81
+ encodeSpFloat(
82
+ (intBitsToFloat((encodedValue and PAYLOAD_MASK ).toInt()) * other).toFloat())
83
+ else -> doubleToRawLongBits(Double .NaN )
84
+ })
85
+ }
86
+
87
+ operator fun times (other : Int ): Dimen {
88
+ return Dimen (
89
+ when {
90
+ // DP case
91
+ encodedValue and NAN_MASK != NAN_MASK ->
92
+ doubleToRawLongBits(longBitsToDouble(encodedValue) * other)
93
+ // PX case
94
+ encodedValue and PX_FLAG == PX_FLAG ->
95
+ encodePxInt((encodedValue and PAYLOAD_MASK ).toInt() * other)
96
+ // SP case
97
+ encodedValue and SP_FLAG == SP_FLAG ->
98
+ encodeSpFloat(intBitsToFloat(encodedValue.and (PAYLOAD_MASK ).toInt()) * other)
99
+ else -> doubleToRawLongBits(Double .NaN )
100
+ })
101
+ }
102
+
103
+ operator fun div (other : Double ): Dimen = this * (1.0 / other)
104
+
105
+ operator fun div (other : Float ): Dimen = this * (1f / other)
106
+
107
+ operator fun div (other : Int ): Dimen {
108
+ return Dimen (
109
+ when {
110
+ // DP case
111
+ encodedValue and NAN_MASK != NAN_MASK ->
112
+ doubleToRawLongBits(longBitsToDouble(encodedValue) / other)
113
+ // PX case
114
+ encodedValue and PX_FLAG == PX_FLAG ->
115
+ encodePxInt((encodedValue and PAYLOAD_MASK ).toInt() / other)
116
+ // SP case
117
+ encodedValue and SP_FLAG == SP_FLAG ->
118
+ encodeSpFloat(intBitsToFloat(encodedValue.and (PAYLOAD_MASK ).toInt()) / other)
119
+ else -> doubleToRawLongBits(Double .NaN )
120
+ })
121
+ }
122
+
123
+ operator fun unaryMinus (): Dimen = this * - 1
52
124
}
53
125
126
+ operator fun Double.times (other : Dimen ): Dimen = other * this
127
+
128
+ operator fun Float.times (other : Dimen ): Dimen = other * this
129
+
130
+ operator fun Int.times (other : Dimen ): Dimen = other * this
131
+
54
132
/* * Creates a Dimen with a constant dp (density-independent pixels) value. */
55
133
inline val Int .dp: Dimen
56
134
get() = Dimen (doubleToRawLongBits(this .toDouble()))
0 commit comments