mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Lerp.
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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))
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
3
time.go
3
time.go
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user