Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.62 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func pow(x, n, lim float64) float64 {
  9.     if v := math.Pow(x, n); v < lim {
  10.         return v
  11.     } else {
  12.         // v still defined.
  13.         fmt. Printf("%g >= %g\n", v, lim)
  14. //        return v
  15.     }
  16.     // v no longer defined.
  17.     // unless specified in "else" block, must be specified here. Will only be invoked when "if" is not true.
  18.     return lim
  19. }
  20.  
  21. func main() {
  22.     var pow_vals = [][]float64{
  23.         {3, 2, 10},
  24.         {3, 3, 10},
  25.     }
  26.  
  27.     for _, powval := range pow_vals {
  28.         fmt.Println( pow(powval[0], powval[1], powval[2]) )
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement