Skip to content

Commit f3fcb50

Browse files
duvenaudaxch
authored andcommitted
Replace floating point sizing formula in stack with integer operations.
1 parent 82e6de6 commit f3fcb50

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/prelude.dx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,8 +2477,7 @@ struct Stack(h:Heap, a|Data) =
24772477

24782478
def ensure_size_at_least(req_size:Nat) -> {State h} () =
24792479
if req_size > self.buf_size() then
2480-
-- TODO: maybe this should use integer arithmetic?
2481-
new_buf_size = f_to_n $ 2.0 `pow` (ceil $ log2 $ n_to_f req_size)
2480+
new_buf_size = intpow2 (1 + natlog2 req_size)
24822481
buf = self.unsafe_get_buffer()
24832482
logical_size = self.size()
24842483
cur_data = get $ unsafe_coerce(to=Ref(h, Fin logical_size => a), buf)

0 commit comments

Comments
 (0)