mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 22:04:21 +00:00
These conversion routines accept a `round` argument to control how the result is rounded and return whether the result is exact. Most callers wanted this functionality and had hacks around it being missing. Also delete `std.math.big.rational` because it was only being used for float conversion, and using rationals for that is a lot more complex than necessary. It also required an allocator, whereas the new integer routines only need to be passed enough memory to store the result.
25 lines
746 B
Zig
25 lines
746 B
Zig
const std = @import("../std.zig");
|
|
const assert = std.debug.assert;
|
|
|
|
pub const int = @import("big/int.zig");
|
|
pub const Limb = usize;
|
|
const limb_info = @typeInfo(Limb).int;
|
|
pub const SignedLimb = std.meta.Int(.signed, limb_info.bits);
|
|
pub const DoubleLimb = std.meta.Int(.unsigned, 2 * limb_info.bits);
|
|
pub const HalfLimb = std.meta.Int(.unsigned, limb_info.bits / 2);
|
|
pub const SignedDoubleLimb = std.meta.Int(.signed, 2 * limb_info.bits);
|
|
pub const Log2Limb = std.math.Log2Int(Limb);
|
|
|
|
comptime {
|
|
assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits);
|
|
assert(limb_info.signedness == .unsigned);
|
|
}
|
|
|
|
test {
|
|
_ = int;
|
|
_ = Limb;
|
|
_ = SignedLimb;
|
|
_ = DoubleLimb;
|
|
_ = SignedDoubleLimb;
|
|
_ = Log2Limb;
|
|
}
|