Source file tour/methods/methods-continued.go

     1  //go:build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"math"
     8  )
     9  
    10  type MyFloat float64
    11  
    12  func (f MyFloat) Abs() float64 {
    13  	if f < 0 {
    14  		return float64(-f)
    15  	}
    16  	return float64(f)
    17  }
    18  
    19  func main() {
    20  	f := MyFloat(-math.Sqrt2)
    21  	fmt.Println(f.Abs())
    22  }
    23  

View as plain text