-
Notifications
You must be signed in to change notification settings - Fork 7
/
float32.go
217 lines (187 loc) · 4.66 KB
/
float32.go
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package ameda
import (
"fmt"
"math"
)
// Float32ToInterface converts float32 to interface.
func Float32ToInterface(v float32) interface{} {
return v
}
// Float32ToInterfacePtr converts float32 to *interface.
func Float32ToInterfacePtr(v float32) *interface{} {
r := Float32ToInterface(v)
return &r
}
// Float32ToString converts float32 to string.
func Float32ToString(v float32) string {
return fmt.Sprintf("%f", v)
}
// Float32ToStringPtr converts float32 to *string.
func Float32ToStringPtr(v float32) *string {
r := Float32ToString(v)
return &r
}
// Float32ToBool converts float32 to bool.
func Float32ToBool(v float32) bool {
return v != 0
}
// Float32ToBoolPtr converts float32 to *bool.
func Float32ToBoolPtr(v float32) *bool {
r := Float32ToBool(v)
return &r
}
// Float32ToFloat32Ptr converts float32 to *float32.
func Float32ToFloat32Ptr(v float32) *float32 {
return &v
}
// Float32ToFloat64 converts float32 to float64.
func Float32ToFloat64(v float32) float64 {
return float64(v)
}
// Float32ToFloat64Ptr converts float32 to *float64.
func Float32ToFloat64Ptr(v float32) *float64 {
r := Float32ToFloat64(v)
return &r
}
// Float32ToInt converts float32 to int.
func Float32ToInt(v float32) (int, error) {
if Host64bit {
if v > math.MaxInt64 || v < math.MinInt64 {
return 0, errOverflowValue
}
} else {
if v > math.MaxInt32 || v < math.MinInt32 {
return 0, errOverflowValue
}
}
return int(v), nil
}
// Float32ToInt8 converts float32 to int8.
func Float32ToInt8(v float32) (int8, error) {
if v > math.MaxInt8 || v < math.MinInt8 {
return 0, errOverflowValue
}
return int8(v), nil
}
// Float32ToInt8Ptr converts float32 to *int8.
func Float32ToInt8Ptr(v float32) (*int8, error) {
r, err := Float32ToInt8(v)
return &r, err
}
// Float32ToInt16 converts float32 to int16.
func Float32ToInt16(v float32) (int16, error) {
if v > math.MaxInt16 || v < math.MinInt16 {
return 0, errOverflowValue
}
return int16(v), nil
}
// Float32ToInt16Ptr converts float32 to *int16.
func Float32ToInt16Ptr(v float32) (*int16, error) {
r, err := Float32ToInt16(v)
return &r, err
}
// Float32ToInt32 converts float32 to int32.
func Float32ToInt32(v float32) (int32, error) {
if v > math.MaxInt32 || v < math.MinInt32 {
return 0, errOverflowValue
}
return int32(v), nil
}
// Float32ToInt32Ptr converts float32 to *int32.
func Float32ToInt32Ptr(v float32) (*int32, error) {
r, err := Float32ToInt32(v)
return &r, err
}
// Float32ToInt64 converts float32 to int64.
func Float32ToInt64(v float32) (int64, error) {
if v > math.MaxInt64 || v < math.MinInt64 {
return 0, errOverflowValue
}
return int64(v), nil
}
// Float32ToInt64Ptr converts float32 to *int64.
func Float32ToInt64Ptr(v float32) (*int64, error) {
r, err := Float32ToInt64(v)
return &r, err
}
// Float32ToUint converts float32 to uint.
func Float32ToUint(v float32) (uint, error) {
if v < 0 {
return 0, errNegativeValue
}
if Host64bit {
if v > math.MaxUint64 {
return 0, errOverflowValue
}
} else {
if v > math.MaxUint32 {
return 0, errOverflowValue
}
}
return uint(v), nil
}
// Float32ToUintPtr converts float32 to *uint.
func Float32ToUintPtr(v float32) (*uint, error) {
r, err := Float32ToUint(v)
return &r, err
}
// Float32ToUint8 converts float32 to uint8.
func Float32ToUint8(v float32) (uint8, error) {
if v < 0 {
return 0, errNegativeValue
}
if v > math.MaxUint8 {
return 0, errOverflowValue
}
return uint8(v), nil
}
// Float32ToUint8Ptr converts float32 to *uint8.
func Float32ToUint8Ptr(v float32) (*uint8, error) {
r, err := Float32ToUint8(v)
return &r, err
}
// Float32ToUint16 converts float32 to uint16.
func Float32ToUint16(v float32) (uint16, error) {
if v < 0 {
return 0, errNegativeValue
}
if v > math.MaxUint16 {
return 0, errOverflowValue
}
return uint16(v), nil
}
// Float32ToUint16Ptr converts float32 to *uint16.
func Float32ToUint16Ptr(v float32) (*uint16, error) {
r, err := Float32ToUint16(v)
return &r, err
}
// Float32ToUint32 converts float32 to uint32.
func Float32ToUint32(v float32) (uint32, error) {
if v < 0 {
return 0, errNegativeValue
}
if v > math.MaxUint32 {
return 0, errOverflowValue
}
return uint32(v), nil
}
// Float32ToUint32Ptr converts float32 to *uint32.
func Float32ToUint32Ptr(v float32) (*uint32, error) {
r, err := Float32ToUint32(v)
return &r, err
}
// Float32ToUint64 converts float32 to uint64.
func Float32ToUint64(v float32) (uint64, error) {
if v < 0 {
return 0, errNegativeValue
}
if v > math.MaxUint64 {
return 0, errOverflowValue
}
return uint64(v), nil
}
// Float32ToUint64Ptr converts float32 to *uint64.
func Float32ToUint64Ptr(v float32) (*uint64, error) {
r, err := Float32ToUint64(v)
return &r, err
}