Add arbitrary-precision integer to std

A few notes on the implementation:

 - Any unsigned power of two integer type less than 64 bits in size is supported
 as a Limb type.
 - The algorithms used are kept simple for the moment. More complicated
 algorithms are generally only more useful as integer sizes increase a
 lot and I don't expect our current usage to be used for this purpose
 just yet.
 - All branches (practically) have been covered by tests.

See 986a2b3243/bench
for rough performance comparison numbers.

Closes #364.
master
Marc Tiehuis 2018-06-09 10:24:20 +12:00
parent 0a95b0f1ff
commit dc8bda7e02
4 changed files with 2033 additions and 0 deletions

View File

@ -464,6 +464,7 @@ set(ZIG_STD_FILES
"math/atan.zig"
"math/atan2.zig"
"math/atanh.zig"
"math/big/int.zig"
"math/cbrt.zig"
"math/ceil.zig"
"math/complex/abs.zig"

5
std/math/big/index.zig Normal file
View File

@ -0,0 +1,5 @@
pub use @import("int.zig");
test "math.big" {
_ = @import("int.zig");
}

2023
std/math/big/int.zig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -132,6 +132,8 @@ pub const tan = @import("tan.zig").tan;
pub const complex = @import("complex/index.zig");
pub const Complex = complex.Complex;
pub const big = @import("big/index.zig");
test "math" {
_ = @import("nan.zig");
_ = @import("isnan.zig");
@ -177,6 +179,8 @@ test "math" {
_ = @import("tan.zig");
_ = @import("complex/index.zig");
_ = @import("big/index.zig");
}
pub fn min(x: var, y: var) @typeOf(x + y) {