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

@@ -6,10 +6,9 @@ import (
"math" "math"
"slices" "slices"
"github.com/ncruces/sort/quick"
"github.com/ncruces/go-sqlite3" "github.com/ncruces/go-sqlite3"
"github.com/ncruces/go-sqlite3/internal/util" "github.com/ncruces/go-sqlite3/internal/util"
"github.com/ncruces/sort/quick"
) )
const ( const (
@@ -92,7 +91,7 @@ func (q *percentile) at(pos float64) (float64, error) {
} }
m1 := slices.Min(q.nums[int(i)+1:]) m1 := slices.Min(q.nums[int(i)+1:])
return math.FMA(f, m1, math.FMA(-f, m0, m0)), nil return util.Lerp(m0, m1, f), nil
} }
func (q *percentile) atMore(pos []float64) error { func (q *percentile) atMore(pos []float64) error {

View File

@@ -1,5 +1,7 @@
package util package util
import "math"
func abs(n int) int { func abs(n int) int {
if n < 0 { if n < 0 {
return -n return -n
@@ -20,3 +22,8 @@ func LCM(m, n int) int {
} }
return abs(n) * (abs(m) / GCD(m, n)) 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 ( import (
"math" "math"
"testing" "testing"
"github.com/ncruces/go-sqlite3/internal/util"
) )
func TestUnwrapPointer(t *testing.T) { func TestUnwrapPointer(t *testing.T) {
p := util.Pointer[float64]{Value: math.Pi} p := Pointer[float64]{Value: math.Pi}
if got := util.UnwrapPointer(p); got != math.Pi { if got := UnwrapPointer(p); got != math.Pi {
t.Errorf("want π, got %v", got) t.Errorf("want π, got %v", got)
} }
} }

View File

@@ -7,13 +7,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/ncruces/julianday"
"github.com/ncruces/go-sqlite3" "github.com/ncruces/go-sqlite3"
"github.com/ncruces/go-sqlite3/driver" "github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed" _ "github.com/ncruces/go-sqlite3/embed"
_ "github.com/ncruces/go-sqlite3/internal/testcfg" _ "github.com/ncruces/go-sqlite3/internal/testcfg"
"github.com/ncruces/go-sqlite3/vfs/memdb" "github.com/ncruces/go-sqlite3/vfs/memdb"
"github.com/ncruces/julianday"
) )
func TestJSON(t *testing.T) { func TestJSON(t *testing.T) {

View File

@@ -6,9 +6,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/ncruces/julianday"
"github.com/ncruces/go-sqlite3/internal/util" "github.com/ncruces/go-sqlite3/internal/util"
"github.com/ncruces/julianday"
) )
// TimeFormat specifies how to encode/decode time values. // TimeFormat specifies how to encode/decode time values.