feat: add Log

This commit is contained in:
dudaodong committed 2023-06-13 14:59:30 +08:00
1 parent f3382ceac9
commit 4bc43f3278
4 files changed
+112 -27

No files matched your search

+5
View File
@@ -189,3 +189,8 @@ func Cos(radian float64, precision ...int) float64 {
func Sin(radian float64, precision ...int) float64 {
return Cos((math.Pi / 2) - radian)
}
// Log returns the logarithm of base n.
func Log(n, base float64) float64 {
return math.Log(n) / math.Log(base)
}
+8
View File
@@ -172,3 +172,11 @@ func TestSin(t *testing.T) {
assert.EqualValues(0, Sin(math.Pi))
assert.EqualValues(1, Sin(math.Pi/2))
}
func TestLog(t *testing.T) {
assert := internal.NewAssert(t, "TestLog")
assert.EqualValues(3, Log(8, 2))
assert.EqualValues(3, TruncRound(Log(27, 3), 0))
assert.EqualValues(2.32, TruncRound(Log(5, 2), 2))
}