Skip to content

Commit b59c65e

Browse files
authored
Merge pull request #2102 from ziglang/big.int-additions
Add big.Rational type to std
2 parents dff2015 + 78af62a commit b59c65e

File tree

5 files changed

+1303
-249
lines changed

5 files changed

+1303
-249
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ set(ZIG_STD_FILES
521521
"math/atanh.zig"
522522
"math/big.zig"
523523
"math/big/int.zig"
524+
"math/big/rational.zig"
524525
"math/cbrt.zig"
525526
"math/ceil.zig"
526527
"math/complex.zig"

src-self-hosted/value.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,21 +538,21 @@ pub const Value = struct {
538538
switch (self.base.typ.id) {
539539
Type.Id.Int => {
540540
const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
541-
if (self.big_int.len == 0) {
541+
if (self.big_int.len() == 0) {
542542
return llvm.ConstNull(type_ref);
543543
}
544-
const unsigned_val = if (self.big_int.len == 1) blk: {
544+
const unsigned_val = if (self.big_int.len() == 1) blk: {
545545
break :blk llvm.ConstInt(type_ref, self.big_int.limbs[0], @boolToInt(false));
546546
} else if (@sizeOf(std.math.big.Limb) == @sizeOf(u64)) blk: {
547547
break :blk llvm.ConstIntOfArbitraryPrecision(
548548
type_ref,
549-
@intCast(c_uint, self.big_int.len),
549+
@intCast(c_uint, self.big_int.len()),
550550
@ptrCast([*]u64, self.big_int.limbs.ptr),
551551
);
552552
} else {
553553
@compileError("std.math.Big.Int.Limb size does not match LLVM");
554554
};
555-
return if (self.big_int.positive) unsigned_val else llvm.ConstNeg(unsigned_val);
555+
return if (self.big_int.isPositive()) unsigned_val else llvm.ConstNeg(unsigned_val);
556556
},
557557
Type.Id.ComptimeInt => unreachable,
558558
else => unreachable,

std/math/big.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
pub use @import("big/int.zig");
2+
pub use @import("big/rational.zig");
23

34
test "math.big" {
45
_ = @import("big/int.zig");
6+
_ = @import("big/rational.zig");
57
}

0 commit comments

Comments
 (0)