example of method on a file-specific type
This commit is contained in:
parent
64b1c50ed9
commit
dbcd180706
@ -19,9 +19,23 @@ func (v *vertex) scale(s float64) {
|
|||||||
v.y *= s
|
v.y *= s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type myfloat float64
|
||||||
|
|
||||||
|
func (f myfloat) abs() float64 {
|
||||||
|
if f < 0 {
|
||||||
|
return float64(-f)
|
||||||
|
}
|
||||||
|
return float64(f)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
v := vertex{1.1, 2.2}
|
v := vertex{1.1, 2.2}
|
||||||
fmt.Println(v.abs())
|
fmt.Println(v.abs())
|
||||||
v.scale(12)
|
v.scale(12)
|
||||||
fmt.Println(v.abs())
|
fmt.Println(v.abs())
|
||||||
|
|
||||||
|
f := myfloat(12.23)
|
||||||
|
fmt.Println(f.abs())
|
||||||
|
fmt.Println(-f)
|
||||||
|
fmt.Println((-f).abs())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user