rat.go 660 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) 2014 The mathutil Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package mathutil // import "modernc.org/mathutil"
  5. // QCmpUint32 compares a/b and c/d and returns:
  6. //
  7. // -1 if a/b < c/d
  8. // 0 if a/b == c/d
  9. // +1 if a/b > c/d
  10. func QCmpUint32(a, b, c, d uint32) int {
  11. switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); {
  12. case x < y:
  13. return -1
  14. case x == y:
  15. return 0
  16. default: // x > y
  17. return 1
  18. }
  19. }
  20. // QScaleUint32 returns a such that a/b >= c/d.
  21. func QScaleUint32(b, c, d uint32) (a uint64) {
  22. return 1 + (uint64(b)*uint64(c))/uint64(d)
  23. }