a := big.NewRat(1, 2) b := big.NewRat(3, 4) c := big.NewRat(5, 6) fmt.Println(a.Cmp(b)) // Output: -1 fmt.Println(b.Cmp(a)) // Output: 1 fmt.Println(a.Cmp(a)) // Output: 0 fmt.Println(a.Cmp(c)) // Output: -1
a := big.NewRat(1, 65536) b := big.NewRat(1, 256) c := big.NewRat(1, 16) fmt.Println(a.Cmp(b)) // Output: -1 fmt.Println(b.Cmp(c)) // Output: -1 fmt.Println(a.Cmp(c)) // Output: -1In this example, we create three Rat values with different denominators. The first comparison returns -1 because 1/65536 is less than 1/256. The second comparison returns -1 because 1/256 is less than 1/16. The third comparison returns -1 because 1/65536 is less than 1/16. Package: math/big