Skip to content

Commit

Permalink
Merge pull request #2102 from ziglang/big.int-additions
Browse files Browse the repository at this point in the history
Add big.Rational type to std
  • Loading branch information
tiehuis authored Apr 11, 2019
2 parents dff2015 + 78af62a commit b59c65e
Show file tree
Hide file tree
Showing 5 changed files with 1,303 additions and 249 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ set(ZIG_STD_FILES
"math/atanh.zig"
"math/big.zig"
"math/big/int.zig"
"math/big/rational.zig"
"math/cbrt.zig"
"math/ceil.zig"
"math/complex.zig"
Expand Down
8 changes: 4 additions & 4 deletions src-self-hosted/value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,21 @@ pub const Value = struct {
switch (self.base.typ.id) {
Type.Id.Int => {
const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
if (self.big_int.len == 0) {
if (self.big_int.len() == 0) {
return llvm.ConstNull(type_ref);
}
const unsigned_val = if (self.big_int.len == 1) blk: {
const unsigned_val = if (self.big_int.len() == 1) blk: {
break :blk llvm.ConstInt(type_ref, self.big_int.limbs[0], @boolToInt(false));
} else if (@sizeOf(std.math.big.Limb) == @sizeOf(u64)) blk: {
break :blk llvm.ConstIntOfArbitraryPrecision(
type_ref,
@intCast(c_uint, self.big_int.len),
@intCast(c_uint, self.big_int.len()),
@ptrCast([*]u64, self.big_int.limbs.ptr),
);
} else {
@compileError("std.math.Big.Int.Limb size does not match LLVM");
};
return if (self.big_int.positive) unsigned_val else llvm.ConstNeg(unsigned_val);
return if (self.big_int.isPositive()) unsigned_val else llvm.ConstNeg(unsigned_val);
},
Type.Id.ComptimeInt => unreachable,
else => unreachable,
Expand Down
2 changes: 2 additions & 0 deletions std/math/big.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use @import("big/int.zig");
pub use @import("big/rational.zig");

test "math.big" {
_ = @import("big/int.zig");
_ = @import("big/rational.zig");
}
Loading

0 comments on commit b59c65e

Please sign in to comment.