Skip to content
/ afloat Public

afloat provides atomic operations for float types

Notifications You must be signed in to change notification settings

klasrak/afloat

Repository files navigation

afloat

The afloat package provides a wrapper for atomic operations for the float32 and float64 types, which are not natively supported by the sync/atomic package.

Coverage Coverage Go

How to use - WIP

package main

import (
	"fmt"
	"sync"

	"github.com/klasrak/afloat"
)

func main() {
	var (
		f32 afloat.Float32
		f64 afloat.Float64
		wg  sync.WaitGroup
	)

	for i := 0; i < 100; i++ {
		wg.Add(1)

		go func() {
			defer wg.Done()
			f32.Add(1.0) // Concurrently add a float32 to f32
			f64.Add(1.0) // Concurrently add a float64 to f64
		}()
	}

	wg.Wait()

	fmt.Println(f32.Load()) // 100
	fmt.Println(f64.Load()) // 100
}

About

afloat provides atomic operations for float types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages