go-learning/tour_of_go/l5/methods-continued.go

21 lines
219 B
Go
Raw Normal View History

2025-08-31 16:38:50 +00:00
package main
import (
"fmt"
"math"
)
type MyFloat float64
func (f MyFloat) Abs() float64 {
if f < 0 {
return float64(-f)
}
return float64(f)
}
func main() {
f := MyFloat(-math.Sqrt2)
fmt.Println(f.Abs())
}