authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-10-04 03:38:42-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-10-08 01:15:20+02:00
log7c17f4c4b37804b8f7c01d85e0e4c54bdcf34e1d
tree2f74f7319e503093dbf5fff43f485e6e35210cec
parent26fd35ff902cb0f68ada18706e7f670b4aac3d4a

math: simplify code


2 files changed, 3 insertions(+), 3 deletions(-)

lib/std/math/big/int.zig+1-1
...@@ -35,7 +35,7 @@ const constants: Constants = blk: {...@@ -35,7 +35,7 @@ const constants: Constants = blk: {
35 digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb)));35 digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb)));
36 bases[base] = std.math.pow(Limb, base, digits_per_limb[base]);36 bases[base] = std.math.pow(Limb, base, digits_per_limb[base]);
37 }37 }
38 break :blk Constants{ .big_bases = bases, .digits_per_limb = digits_per_limb };38 break :blk .{ .big_bases = bases, .digits_per_limb = digits_per_limb };
39};39};
4040
41/// Returns the number of limbs needed to store `scalar`, which must be a41/// Returns the number of limbs needed to store `scalar`, which must be a
lib/std/math/log10.zig+2-2
...@@ -58,9 +58,9 @@ pub fn log10_int(x: anytype) std.math.Log2Int(@TypeOf(x)) {...@@ -58,9 +58,9 @@ pub fn log10_int(x: anytype) std.math.Log2Int(@TypeOf(x)) {
58 var log: u32 = 0;58 var log: u32 = 0;
5959
60 inline for (0..11) |i| {60 inline for (0..11) |i| {
61 const num_digits = (1 << (11 - i)) * 5;
61 // Unnecessary branches should be removed by the compiler62 // Unnecessary branches should be removed by the compiler
62 if (bit_size > (1 << (11 - i)) * 5 * @log2(10.0) and val >= pow10((1 << (11 - i)) * 5)) {63 if (bit_size > num_digits * @log2(10.0) and val >= pow10(num_digits)) {
63 const num_digits = (1 << (11 - i)) * 5;
64 val /= pow10(num_digits);64 val /= pow10(num_digits);
65 log += num_digits;65 log += num_digits;
66 }66 }