| ... | ... | @@ -334,13 +334,13 @@ pub const Rational = struct { |
| 334 | 334 | /// Returns math.Order.lt, math.Order.eq, math.Order.gt if a < b, a == b or a |
| 335 | 335 | /// > b respectively. |
| 336 | 336 | pub fn order(a: Rational, b: Rational) !math.Order { |
| 337 | | return cmpInternal(a, b, true); |
| 337 | return cmpInternal(a, b, false); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /// Returns math.Order.lt, math.Order.eq, math.Order.gt if |a| < |b|, |a| == |
| 341 | 341 | /// |b| or |a| > |b| respectively. |
| 342 | 342 | pub fn orderAbs(a: Rational, b: Rational) !math.Order { |
| 343 | | return cmpInternal(a, b, false); |
| 343 | return cmpInternal(a, b, true); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // p/q > x/y iff p*y > x*q |
| ... | ... | @@ -704,6 +704,18 @@ test "big.rational order" { |
| 704 | 704 | try testing.expect((try a.order(b)) == .eq); |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | test "big.rational order/orderAbs with negative" { |
| 708 | var a = try Rational.init(testing.allocator); |
| 709 | defer a.deinit(); |
| 710 | var b = try Rational.init(testing.allocator); |
| 711 | defer b.deinit(); |
| 712 | |
| 713 | try a.setRatio(1, 1); |
| 714 | try b.setRatio(-2, 1); |
| 715 | try testing.expect((try a.order(b)) == .gt); |
| 716 | try testing.expect((try a.orderAbs(b)) == .lt); |
| 717 | } |
| 718 | |
| 707 | 719 | test "big.rational add single-limb" { |
| 708 | 720 | var a = try Rational.init(testing.allocator); |
| 709 | 721 | defer a.deinit(); |