File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -67,34 +67,34 @@ func (v *Int) Set(value int64) {
67
67
68
68
// Float is a 64-bit float variable that satisfies the Var interface.
69
69
type Float struct {
70
- f uint64
70
+ f atomic. Uint64
71
71
}
72
72
73
73
func (v * Float ) Value () float64 {
74
- return math .Float64frombits (atomic . LoadUint64 ( & v .f ))
74
+ return math .Float64frombits (v .f . Load ( ))
75
75
}
76
76
77
77
func (v * Float ) String () string {
78
78
return strconv .FormatFloat (
79
- math .Float64frombits (atomic . LoadUint64 ( & v .f )), 'g' , - 1 , 64 )
79
+ math .Float64frombits (v .f . Load ( )), 'g' , - 1 , 64 )
80
80
}
81
81
82
82
// Add adds delta to v.
83
83
func (v * Float ) Add (delta float64 ) {
84
84
for {
85
- cur := atomic . LoadUint64 ( & v .f )
85
+ cur := v .f . Load ( )
86
86
curVal := math .Float64frombits (cur )
87
87
nxtVal := curVal + delta
88
88
nxt := math .Float64bits (nxtVal )
89
- if atomic . CompareAndSwapUint64 ( & v .f , cur , nxt ) {
89
+ if v .f . CompareAndSwap ( cur , nxt ) {
90
90
return
91
91
}
92
92
}
93
93
}
94
94
95
95
// Set sets v to value.
96
96
func (v * Float ) Set (value float64 ) {
97
- atomic . StoreUint64 ( & v .f , math .Float64bits (value ))
97
+ v .f . Store ( math .Float64bits (value ))
98
98
}
99
99
100
100
// Map is a string-to-Var map variable that satisfies the Var interface.
Original file line number Diff line number Diff line change @@ -87,8 +87,8 @@ func BenchmarkIntSet(b *testing.B) {
87
87
func TestFloat (t * testing.T ) {
88
88
RemoveAll ()
89
89
reqs := NewFloat ("requests-float" )
90
- if reqs .f != 0.0 {
91
- t .Errorf ("reqs.f = %v, want 0" , reqs .f )
90
+ if reqs .f . Load () != 0.0 {
91
+ t .Errorf ("reqs.f = %v, want 0" , reqs .f . Load () )
92
92
}
93
93
if reqs != Get ("requests-float" ).(* Float ) {
94
94
t .Errorf ("Get() failed." )
You can’t perform that action at this time.
0 commit comments