| 152 | } |
| 153 | |
| 154 | func Int(x any) any { |
| 155 | switch x := x.(type) { |
| 156 | case float32: |
| 157 | return int(x) |
| 158 | case float64: |
| 159 | return int(x) |
| 160 | case int: |
| 161 | return x |
| 162 | case int8: |
| 163 | return int(x) |
| 164 | case int16: |
| 165 | return int(x) |
| 166 | case int32: |
| 167 | return int(x) |
| 168 | case int64: |
| 169 | return int(x) |
| 170 | case uint: |
| 171 | return int(x) |
| 172 | case uint8: |
| 173 | return int(x) |
| 174 | case uint16: |
| 175 | return int(x) |
| 176 | case uint32: |
| 177 | return int(x) |
| 178 | case uint64: |
| 179 | return int(x) |
| 180 | case string: |
| 181 | i, err := strconv.Atoi(x) |
| 182 | if err != nil { |
| 183 | panic(fmt.Sprintf("invalid operation: int(%s)", x)) |
| 184 | } |
| 185 | return i |
| 186 | default: |
| 187 | val := reflect.ValueOf(x) |
| 188 | if val.CanConvert(integerType) { |
| 189 | return val.Convert(integerType).Interface() |
| 190 | } |
| 191 | panic(fmt.Sprintf("invalid operation: int(%T)", x)) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | func Float(x any) any { |
| 196 | switch x := x.(type) { |