@@ -90,6 +90,50 @@ func (v *int64Value) String() string {
90
90
return strconv .FormatInt (int64 (* v ), 10 )
91
91
}
92
92
93
+ type float32Value float32
94
+
95
+ func newFloat32Value (x float32 , p * float32 ) * float32Value {
96
+ * p = x
97
+ return (* float32Value )(p )
98
+ }
99
+
100
+ func (v * float32Value ) Set (x string ) error {
101
+ n , err := strconv .ParseFloat (x , 32 )
102
+ * v = float32Value (n )
103
+ if err != nil {
104
+ if ne , ok := err .(* strconv.NumError ); ok {
105
+ return errors .New ("invalid 32-bit float " + strconv .Quote (ne .Num ) + ": " + ne .Err .Error ())
106
+ }
107
+ }
108
+ return err
109
+ }
110
+
111
+ func (v * float32Value ) String () string {
112
+ return strconv .FormatFloat (float64 (* v ), 'g' , - 1 , 32 )
113
+ }
114
+
115
+ type float64Value float64
116
+
117
+ func newFloat64Value (x float64 , p * float64 ) * float64Value {
118
+ * p = x
119
+ return (* float64Value )(p )
120
+ }
121
+
122
+ func (v * float64Value ) Set (x string ) error {
123
+ n , err := strconv .ParseFloat (x , 64 )
124
+ * v = float64Value (n )
125
+ if err != nil {
126
+ if ne , ok := err .(* strconv.NumError ); ok {
127
+ return errors .New ("invalid 64-bit float " + strconv .Quote (ne .Num ) + ": " + ne .Err .Error ())
128
+ }
129
+ }
130
+ return err
131
+ }
132
+
133
+ func (v * float64Value ) String () string {
134
+ return strconv .FormatFloat (float64 (* v ), 'g' , - 1 , 64 )
135
+ }
136
+
93
137
type durationValue time.Duration
94
138
95
139
func newDurationValue (x time.Duration , p * time.Duration ) * durationValue {
@@ -234,6 +278,22 @@ func (v *VarSet) Int64(name string, usage string) *int64 {
234
278
return p
235
279
}
236
280
281
+ // Float32 defines an float32 variable with specified name, usage string and validation checks.
282
+ // The return value is the address of an float32 variable that stores the value of the variable.
283
+ func (v * VarSet ) Float32 (name string , usage string ) * float32 {
284
+ p := new (float32 )
285
+ v .Var (newFloat32Value (0 , p ), name , usage )
286
+ return p
287
+ }
288
+
289
+ // Float64 defines an float64 variable with specified name, usage string and validation checks.
290
+ // The return value is the address of an float64 variable that stores the value of the variable.
291
+ func (v * VarSet ) Float64 (name string , usage string ) * float64 {
292
+ p := new (float64 )
293
+ v .Var (newFloat64Value (0 , p ), name , usage )
294
+ return p
295
+ }
296
+
237
297
// Bool defines a bool variable with specified name, usage string and validation checks.
238
298
// The return value is the address of a bool variable that stores the value of the variable.
239
299
func (v * VarSet ) Bool (name string , usage string ) * bool {
@@ -414,6 +474,18 @@ func Int64(name string, usage string) *int64 {
414
474
return CmdVar .Int64 (name , usage )
415
475
}
416
476
477
+ // Float32 defines an float32 variable with specified name and usage string.
478
+ // The return value is the address of an int variable that stores the value of the variable.
479
+ func Float32 (name string , usage string ) * float32 {
480
+ return CmdVar .Float32 (name , usage )
481
+ }
482
+
483
+ // Float64 defines an float64 variable with specified name and usage string.
484
+ // The return value is the address of an int variable that stores the value of the variable.
485
+ func Float64 (name string , usage string ) * float64 {
486
+ return CmdVar .Float64 (name , usage )
487
+ }
488
+
417
489
// Bool defines a bool variable with specified name and usage string.
418
490
// The return value is the address of a bool variable that stores the value of the variable.
419
491
func Bool (name string , usage string ) * bool {
0 commit comments