AsInt32 returns the value as 32-bit integer if possible, or returns an error if not possible. The method will set expr.resInt to the value of this int32 if it is successful, avoiding the need to call the method again.
()
| 214 | // value of this int32 if it is successful, avoiding the need to call |
| 215 | // the method again. |
| 216 | func (expr *NumVal) AsInt32() (int32, error) { |
| 217 | intVal, ok := expr.AsConstantInt() |
| 218 | if !ok { |
| 219 | return 0, errConstNotInt |
| 220 | } |
| 221 | i, exact := constant.Int64Val(intVal) |
| 222 | if !exact { |
| 223 | return 0, errConstOutOfRange32 |
| 224 | } |
| 225 | if i > math.MaxInt32 || i < math.MinInt32 { |
| 226 | return 0, errConstOutOfRange32 |
| 227 | } |
| 228 | expr.resInt = DInt(i) |
| 229 | return int32(i), nil |
| 230 | } |
| 231 | |
| 232 | // AsConstantValue returns the value as a constant numerical value, with the proper sign |
| 233 | // as given by expr.negative. |
no test coverage detected