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