source: code/trunk/vendor/modernc.org/mathutil/rat.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 669 bytes
Line 
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
5package mathutil // import "modernc.org/mathutil"
6
7// QCmpUint32 compares a/b and c/d and returns:
8//
9// -1 if a/b < c/d
10// 0 if a/b == c/d
11// +1 if a/b > c/d
12//
13func QCmpUint32(a, b, c, d uint32) int {
14 switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); {
15 case x < y:
16 return -1
17 case x == y:
18 return 0
19 default: // x > y
20 return 1
21 }
22}
23
24// QScaleUint32 returns a such that a/b >= c/d.
25func QScaleUint32(b, c, d uint32) (a uint64) {
26 return 1 + (uint64(b)*uint64(c))/uint64(d)
27}
Note: See TracBrowser for help on using the repository browser.