2017-01-22 17:29:48 +02:00
|
|
|
package jsoniter
|
|
|
|
|
2017-01-22 17:38:55 +02:00
|
|
|
import (
|
2017-01-26 10:33:16 +02:00
|
|
|
"strconv"
|
2017-01-22 17:38:55 +02:00
|
|
|
)
|
|
|
|
|
2017-01-26 10:33:16 +02:00
|
|
|
type floatAny struct {
|
|
|
|
baseAny
|
|
|
|
val float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) Parse() *Iterator {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ValueType() ValueType {
|
2017-08-05 01:10:15 +02:00
|
|
|
return NumberValue
|
2017-01-26 10:33:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 15:21:20 +02:00
|
|
|
func (any *floatAny) MustBeValid() Any {
|
|
|
|
return any
|
|
|
|
}
|
|
|
|
|
2017-01-26 10:33:16 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-01-29 10:55:32 +02:00
|
|
|
func (any *floatAny) ToUint() uint {
|
2017-07-03 18:19:41 +02:00
|
|
|
if any.val > 0 {
|
|
|
|
return uint(any.val)
|
|
|
|
}
|
2017-07-04 19:21:33 +02:00
|
|
|
return 0
|
2017-01-29 10:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToUint32() uint32 {
|
2017-07-04 19:21:33 +02:00
|
|
|
if any.val > 0 {
|
|
|
|
return uint32(any.val)
|
|
|
|
}
|
|
|
|
return 0
|
2017-01-29 10:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (any *floatAny) ToUint64() uint64 {
|
2017-07-04 19:21:33 +02:00
|
|
|
if any.val > 0 {
|
|
|
|
return uint64(any.val)
|
|
|
|
}
|
|
|
|
return 0
|
2017-01-29 10:55:32 +02:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:33:16 +02:00
|
|
|
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
|
2017-06-06 17:27:00 +02:00
|
|
|
}
|