From 38ee512a25776976caf787dff53126eed33ff835 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Wed, 12 Oct 2022 08:18:47 -0400 Subject: [PATCH] math.big.int: add `calcLimbLen` doc comment note When trying to allocate memory for functions like `Managed.init` and `Managed.set` on the stack, a comptime-known allocation size is desired. The doc comments for these functions indicate that `calcLimbLen` can be used to determine how many limbs to allocate, but if `value` is not comptime-known, then neither is `calcLimbLen(value)`. However, an upper bound on the allocation size is still computable at comptime in this case, so this note documents an expression that can be used, rather than trying to add it to every doc comment that mentions `calcLimbLen`. --- lib/std/math/big/int.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index ba582ff843..1c5ac8194d 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -21,6 +21,9 @@ const debug_safety = false; /// Returns the number of limbs needed to store `scalar`, which must be a /// primitive integer value. +/// Note: A comptime-known upper bound of this value that may be used +/// instead if `scalar` is not already comptime-known is +/// `calcTwosCompLimbCount(@typeInfo(@TypeOf(scalar)).Int.bits)` pub fn calcLimbLen(scalar: anytype) usize { if (scalar == 0) { return 1;