@@ -392,6 +392,22 @@ type Type interface {
392
392
// It panics if the type's Kind is not Func.
393
393
// It panics if i is not in the range [0, NumOut()).
394
394
Out (i int ) Type
395
+
396
+ // OverflowComplex reports whether the complex128 x cannot be represented by type t.
397
+ // It panics if t's Kind is not Complex64 or Complex128.
398
+ OverflowComplex (x complex128 ) bool
399
+
400
+ // OverflowFloat reports whether the float64 x cannot be represented by type t.
401
+ // It panics if t's Kind is not Float32 or Float64.
402
+ OverflowFloat (x float64 ) bool
403
+
404
+ // OverflowInt reports whether the int64 x cannot be represented by type t.
405
+ // It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64.
406
+ OverflowInt (x int64 ) bool
407
+
408
+ // OverflowUint reports whether the uint64 x cannot be represented by type t.
409
+ // It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
410
+ OverflowUint (x uint64 ) bool
395
411
}
396
412
397
413
// Constants for the 'meta' byte.
@@ -1081,6 +1097,58 @@ func (t rawType) Out(i int) Type {
1081
1097
panic ("unimplemented: (reflect.Type).Out()" )
1082
1098
}
1083
1099
1100
+ // OverflowComplex reports whether the complex128 x cannot be represented by type t.
1101
+ // It panics if t's Kind is not Complex64 or Complex128.
1102
+ func (t rawType ) OverflowComplex (x complex128 ) bool {
1103
+ k := t .Kind ()
1104
+ switch k {
1105
+ case Complex64 :
1106
+ return overflowFloat32 (real (x )) || overflowFloat32 (imag (x ))
1107
+ case Complex128 :
1108
+ return false
1109
+ }
1110
+ panic ("reflect: OverflowComplex of non-complex type" )
1111
+ }
1112
+
1113
+ // OverflowFloat reports whether the float64 x cannot be represented by type t.
1114
+ // It panics if t's Kind is not Float32 or Float64.
1115
+ func (t rawType ) OverflowFloat (x float64 ) bool {
1116
+ k := t .Kind ()
1117
+ switch k {
1118
+ case Float32 :
1119
+ return overflowFloat32 (x )
1120
+ case Float64 :
1121
+ return false
1122
+ }
1123
+ panic ("reflect: OverflowFloat of non-float type" )
1124
+ }
1125
+
1126
+ // OverflowInt reports whether the int64 x cannot be represented by type t.
1127
+ // It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64.
1128
+ func (t rawType ) OverflowInt (x int64 ) bool {
1129
+ k := t .Kind ()
1130
+ switch k {
1131
+ case Int , Int8 , Int16 , Int32 , Int64 :
1132
+ bitSize := t .Size () * 8
1133
+ trunc := (x << (64 - bitSize )) >> (64 - bitSize )
1134
+ return x != trunc
1135
+ }
1136
+ panic ("reflect: OverflowInt of non-int type" )
1137
+ }
1138
+
1139
+ // OverflowUint reports whether the uint64 x cannot be represented by type t.
1140
+ // It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
1141
+ func (t rawType ) OverflowUint (x uint64 ) bool {
1142
+ k := t .Kind ()
1143
+ switch k {
1144
+ case Uint , Uintptr , Uint8 , Uint16 , Uint32 , Uint64 :
1145
+ bitSize := t .Size () * 8
1146
+ trunc := (x << (64 - bitSize )) >> (64 - bitSize )
1147
+ return x != trunc
1148
+ }
1149
+ panic ("reflect: OverflowUint of non-uint type" )
1150
+ }
1151
+
1084
1152
func (t rawType ) Method (i int ) Method {
1085
1153
panic ("unimplemented: (reflect.Type).Method()" )
1086
1154
}
0 commit comments