TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A faster next-power-of-two algorithm

2 点作者 peripetylabs大约 12 年前

1 comment

ColinWright大约 12 年前
I'm confused by this. Both the algorithms mentioned seem to give the wrong result when N is a power of 2.<p>For example, N=4. Set all the lower bits to 1, giving 7. Increment, giving 8, return 8. But the power of two no less than 4 is 4.<p>Am I missing something?<p>Also, the alleged faster solution is only faster for larger numbers (on a log scale). Sure, there are more of them, but what if your function is called more often for small numbers than large ones?
评论 #5692302 未加载
评论 #5692300 未加载