diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-06 19:06:09 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-09-06 19:45:02 -0700 |
| commit | b7900de1684021ff86c67105e14e34968821ea02 (patch) | |
| tree | b881a288071705ffb8cd65ede5f8e7a1452b6dce /lib/std/math | |
| parent | 20145016ac0d098e8e63d5107a05eca376d1e7bb (diff) | |
| parent | e2bb92b2e27dc54852a0227345e294ae383358fd (diff) | |
| download | zig-b7900de1684021ff86c67105e14e34968821ea02.tar.gz zig-b7900de1684021ff86c67105e14e34968821ea02.zip | |
Merge remote-tracking branch 'origin/master' into llvm15
Diffstat (limited to 'lib/std/math')
| -rw-r--r-- | lib/std/math/big/rational.zig | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig index 895b20d9b5..61e2194eea 100644 --- a/lib/std/math/big/rational.zig +++ b/lib/std/math/big/rational.zig @@ -334,13 +334,13 @@ pub const Rational = struct { /// Returns math.Order.lt, math.Order.eq, math.Order.gt if a < b, a == b or a /// > b respectively. pub fn order(a: Rational, b: Rational) !math.Order { - return cmpInternal(a, b, true); + return cmpInternal(a, b, false); } /// Returns math.Order.lt, math.Order.eq, math.Order.gt if |a| < |b|, |a| == /// |b| or |a| > |b| respectively. pub fn orderAbs(a: Rational, b: Rational) !math.Order { - return cmpInternal(a, b, false); + return cmpInternal(a, b, true); } // p/q > x/y iff p*y > x*q @@ -704,6 +704,18 @@ test "big.rational order" { try testing.expect((try a.order(b)) == .eq); } +test "big.rational order/orderAbs with negative" { + var a = try Rational.init(testing.allocator); + defer a.deinit(); + var b = try Rational.init(testing.allocator); + defer b.deinit(); + + try a.setRatio(1, 1); + try b.setRatio(-2, 1); + try testing.expect((try a.order(b)) == .gt); + try testing.expect((try a.orderAbs(b)) == .lt); +} + test "big.rational add single-limb" { var a = try Rational.init(testing.allocator); defer a.deinit(); |
