Source file tour/basics/numeric-constants.go

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import "fmt"
     6  
     7  const (
     8  	// Create a huge number by shifting a 1 bit left 100 places.
     9  	// In other words, the binary number that is 1 followed by 100 zeroes.
    10  	Big = 1 << 100
    11  	// Shift it right again 99 places, so we end up with 1<<1, or 2.
    12  	Small = Big >> 99
    13  )
    14  
    15  func needInt(x int) int { return x*10 + 1 }
    16  func needFloat(x float64) float64 {
    17  	return x * 0.1
    18  }
    19  
    20  func main() {
    21  	fmt.Println(needInt(Small))
    22  	fmt.Println(needFloat(Small))
    23  	fmt.Println(needFloat(Big))
    24  }
    25  

View as plain text