Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame^] | 1 | package jsoniter |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | ) |
| 6 | |
| 7 | type floatAny struct { |
| 8 | baseAny |
| 9 | val float64 |
| 10 | } |
| 11 | |
| 12 | func (any *floatAny) Parse() *Iterator { |
| 13 | return nil |
| 14 | } |
| 15 | |
| 16 | func (any *floatAny) ValueType() ValueType { |
| 17 | return NumberValue |
| 18 | } |
| 19 | |
| 20 | func (any *floatAny) MustBeValid() Any { |
| 21 | return any |
| 22 | } |
| 23 | |
| 24 | func (any *floatAny) LastError() error { |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | func (any *floatAny) ToBool() bool { |
| 29 | return any.ToFloat64() != 0 |
| 30 | } |
| 31 | |
| 32 | func (any *floatAny) ToInt() int { |
| 33 | return int(any.val) |
| 34 | } |
| 35 | |
| 36 | func (any *floatAny) ToInt32() int32 { |
| 37 | return int32(any.val) |
| 38 | } |
| 39 | |
| 40 | func (any *floatAny) ToInt64() int64 { |
| 41 | return int64(any.val) |
| 42 | } |
| 43 | |
| 44 | func (any *floatAny) ToUint() uint { |
| 45 | if any.val > 0 { |
| 46 | return uint(any.val) |
| 47 | } |
| 48 | return 0 |
| 49 | } |
| 50 | |
| 51 | func (any *floatAny) ToUint32() uint32 { |
| 52 | if any.val > 0 { |
| 53 | return uint32(any.val) |
| 54 | } |
| 55 | return 0 |
| 56 | } |
| 57 | |
| 58 | func (any *floatAny) ToUint64() uint64 { |
| 59 | if any.val > 0 { |
| 60 | return uint64(any.val) |
| 61 | } |
| 62 | return 0 |
| 63 | } |
| 64 | |
| 65 | func (any *floatAny) ToFloat32() float32 { |
| 66 | return float32(any.val) |
| 67 | } |
| 68 | |
| 69 | func (any *floatAny) ToFloat64() float64 { |
| 70 | return any.val |
| 71 | } |
| 72 | |
| 73 | func (any *floatAny) ToString() string { |
| 74 | return strconv.FormatFloat(any.val, 'E', -1, 64) |
| 75 | } |
| 76 | |
| 77 | func (any *floatAny) WriteTo(stream *Stream) { |
| 78 | stream.WriteFloat64(any.val) |
| 79 | } |
| 80 | |
| 81 | func (any *floatAny) GetInterface() interface{} { |
| 82 | return any.val |
| 83 | } |