MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / UsingLog

Function UsingLog

math/power/powvialogarithm.go:16–26  ·  view source on GitHub ↗
(a float64, b float64)

Source from the content-addressed store, hash-verified

14)
15
16func UsingLog(a float64, b float64) float64 {
17 var p float64
18 p = 1
19 if a < 0 && int(b)&1 != 0 {
20 p = -1
21 }
22 log := math.Log(math.Abs(a))
23 exp := math.Exp(b * log)
24 result := exp * p
25 return math.Round(result)
26}

Callers 2

TestUsingLogFunction · 0.85
BenchmarkUsingLogFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestUsingLogFunction · 0.68
BenchmarkUsingLogFunction · 0.68