From 3ef75c6b51499661a6f1aea8cc9d2cd4ec8fb8af Mon Sep 17 00:00:00 2001 From: Richard Wilkes Date: Tue, 17 Sep 2024 18:30:04 -0700 Subject: [PATCH] Add Float64() and Float32() to hashhelper package --- xmath/hashhelper/hashhelper.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xmath/hashhelper/hashhelper.go b/xmath/hashhelper/hashhelper.go index f584ea3..cb7096b 100644 --- a/xmath/hashhelper/hashhelper.go +++ b/xmath/hashhelper/hashhelper.go @@ -11,6 +11,7 @@ package hashhelper import ( "hash" + "math" ) // String writes the given string to the hash. @@ -67,3 +68,13 @@ func Bool[T ~bool](h hash.Hash, data T) { } _, _ = h.Write([]byte{b}) } + +// Float64 writes the given 64-bit float to the hash. +func Float64[T ~float64](h hash.Hash, data T) { + Num64(h, math.Float64bits(float64(data))) +} + +// Float32 writes the given 64-bit float to the hash. +func Float32[T ~float32](h hash.Hash, data T) { + Num32(h, math.Float32bits(float32(data))) +}