(Translated by https://www.hiragana.jp/)
Fix clz return value for zero · spnda/fastgltf@5f5b8af · GitHub
Skip to content

Commit

Permalink
Fix clz return value for zero
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Oct 3, 2024
1 parent e42df8b commit 5f5b8af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fastgltf/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace fastgltf {
#else
// Very naive but working implementation of counting zero bits. Any sane compiler will
// optimise this away, like instead use the bsr x86 instruction.
if (value == 0) return 64;
if (value == 0) return sizeof(T) * 8;
std::uint8_t count = 0;
for (auto i = std::numeric_limits<T>::digits - 1; i > 0; --i) {
if ((value >> i) == 1) {
Expand Down
1 change: 1 addition & 0 deletions tests/vector_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fastgltf/types.hpp>

TEST_CASE("Verify clz", "[vector-tests]") {
REQUIRE(fastgltf::clz<std::uint8_t>(0b00000000) == 8);
REQUIRE(fastgltf::clz<std::uint8_t>(0b00000001) == 7);
REQUIRE(fastgltf::clz<std::uint8_t>(0b00000010) == 6);
REQUIRE(fastgltf::clz<std::uint8_t>(0b00000100) == 5);
Expand Down

0 comments on commit 5f5b8af

Please sign in to comment.