How to find the binary logarithm (Log2) of a number in Go

1 Answer

0 votes
package main 
   
import ( 
    "fmt"
	"math"
) 
   
func main() { 
	res_1 := math.Log2(0) 
    res_2 := math.Log2(1) 
    res_3 := math.Log2(7) 
    res_4 := math.Log2(-1) 
    res_5 := math.Log2(6.86) 
   
    fmt.Printf("%.2f\n", res_1) 
    fmt.Printf("%.2f\n", res_2) 
    fmt.Printf("%.2f\n", res_3) 
    fmt.Printf("%.2f\n", res_4) 
    fmt.Printf("%.2f\n", res_5) 
} 
 
 
 
/*
run:
 
-Inf
0.00
2.81
NaN
2.78

*/

 



answered Aug 4, 2020 by avibootz

Related questions

...