1
0

example of method on a file-specific type

This commit is contained in:
Stephen M. McQuay 2012-08-27 22:32:36 -06:00
parent 64b1c50ed9
commit dbcd180706

View File

@ -19,9 +19,23 @@ func (v *vertex) scale(s float64) {
v.y *= s
}
type myfloat float64
func (f myfloat) abs() float64 {
if f < 0 {
return float64(-f)
}
return float64(f)
}
func main() {
v := vertex{1.1, 2.2}
fmt.Println(v.abs())
v.scale(12)
fmt.Println(v.abs())
f := myfloat(12.23)
fmt.Println(f.abs())
fmt.Println(-f)
fmt.Println((-f).abs())
}