mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-05 01:52:46 +00:00
30 lines
402 B
Go
30 lines
402 B
Go
package util
|
|
|
|
import "math"
|
|
|
|
func abs(n int) int {
|
|
if n < 0 {
|
|
return -n
|
|
}
|
|
return n
|
|
}
|
|
|
|
func GCD(m, n int) int {
|
|
for n != 0 {
|
|
m, n = n, m%n
|
|
}
|
|
return abs(m)
|
|
}
|
|
|
|
func LCM(m, n int) int {
|
|
if n == 0 {
|
|
return 0
|
|
}
|
|
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))
|
|
}
|