This commit is contained in:
Nuno Cruces
2024-10-18 12:57:22 +01:00
parent ace01b2927
commit f18561ee11
5 changed files with 14 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
package util
import "math"
func abs(n int) int {
if n < 0 {
return -n
@@ -20,3 +22,8 @@ func LCM(m, n int) int {
}
return abs(n) * (abs(m) / GCD(m, n))
}
// https://developer.nvidia.com/blog/lerp-faster-cuda/
func Lerp(v0, v1, t float64) float64 {
return math.FMA(t, v1, math.FMA(-t, v0, v0))
}

View File

@@ -1,15 +1,13 @@
package util_test
package util
import (
"math"
"testing"
"github.com/ncruces/go-sqlite3/internal/util"
)
func TestUnwrapPointer(t *testing.T) {
p := util.Pointer[float64]{Value: math.Pi}
if got := util.UnwrapPointer(p); got != math.Pi {
p := Pointer[float64]{Value: math.Pi}
if got := UnwrapPointer(p); got != math.Pi {
t.Errorf("want π, got %v", got)
}
}