summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/json-iterator/go/any_float.go
blob: 35fdb09497fa86e5fbc84ad288cbfe8f012c9521 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package jsoniter

import (
	"strconv"
)

type floatAny struct {
	baseAny
	val float64
}

func (any *floatAny) Parse() *Iterator {
	return nil
}

func (any *floatAny) ValueType() ValueType {
	return NumberValue
}

func (any *floatAny) MustBeValid() Any {
	return any
}

func (any *floatAny) LastError() error {
	return nil
}

func (any *floatAny) ToBool() bool {
	return any.ToFloat64() != 0
}

func (any *floatAny) ToInt() int {
	return int(any.val)
}

func (any *floatAny) ToInt32() int32 {
	return int32(any.val)
}

func (any *floatAny) ToInt64() int64 {
	return int64(any.val)
}

func (any *floatAny) ToUint() uint {
	if any.val > 0 {
		return uint(any.val)
	}
	return 0
}

func (any *floatAny) ToUint32() uint32 {
	if any.val > 0 {
		return uint32(any.val)
	}
	return 0
}

func (any *floatAny) ToUint64() uint64 {
	if any.val > 0 {
		return uint64(any.val)
	}
	return 0
}

func (any *floatAny) ToFloat32() float32 {
	return float32(any.val)
}

func (any *floatAny) ToFloat64() float64 {
	return any.val
}

func (any *floatAny) ToString() string {
	return strconv.FormatFloat(any.val, 'E', -1, 64)
}

func (any *floatAny) WriteTo(stream *Stream) {
	stream.WriteFloat64(any.val)
}

func (any *floatAny) GetInterface() interface{} {
	return any.val
}