github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/esync/sync_atomic_float64.go (about) 1 package esync 2 3 import ( 4 "fmt" 5 "math" 6 "sync/atomic" 7 ) 8 9 // AtomicFloat64 support atomic operation 10 type AtomicFloat64 struct { 11 value uint64 12 } 13 14 func (t *AtomicFloat64) Set(v float64) { 15 atomic.StoreUint64(&t.value, math.Float64bits(v)) 16 } 17 18 func (t *AtomicFloat64) Get() float64 { 19 return math.Float64frombits(atomic.LoadUint64(&t.value)) 20 } 21 22 func (t *AtomicFloat64) Swap(v float64) float64 { 23 return math.Float64frombits(atomic.SwapUint64(&t.value, math.Float64bits(v))) 24 } 25 26 func (t *AtomicFloat64) String() string { 27 return fmt.Sprint(t.Get()) 28 }