Skip to content

Commit b28480c

Browse files
authored
Merge pull request #111 from linksplatform/issue-106-48d2da31
Replace hardcoded bit sizes with named constants in Bit<T> methods
2 parents 2c290a1 + 023a2f5 commit b28480c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • cpp/Platform.Numbers

cpp/Platform.Numbers/Bit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ namespace Platform::Numbers::Bit
5959
{
6060
if (shift < 0)
6161
{
62-
shift = sizeof(T) * 8 + shift;
62+
shift = sizeof(T) * std::numeric_limits<unsigned char>::digits + shift;
6363
}
6464
if (limit < 0)
6565
{
66-
limit = sizeof(T) * 8 + limit;
66+
limit = sizeof(T) * std::numeric_limits<unsigned char>::digits + limit;
6767
}
6868
auto sourceMask = ~(std::numeric_limits<T>::max() << limit) & std::numeric_limits<T>::max();
6969
auto targetMask = ~(sourceMask << shift);
@@ -75,11 +75,11 @@ namespace Platform::Numbers::Bit
7575
{
7676
if (shift < 0)
7777
{
78-
shift = sizeof(T) * 8 + shift;
78+
shift = sizeof(T) * std::numeric_limits<unsigned char>::digits + shift;
7979
}
8080
if (limit < 0)
8181
{
82-
limit = sizeof(T) * 8 + limit;
82+
limit = sizeof(T) * std::numeric_limits<unsigned char>::digits + limit;
8383
}
8484
auto sourceMask = ~(std::numeric_limits<T>::max() << limit) & std::numeric_limits<T>::max();
8585
auto targetMask = sourceMask << shift;

0 commit comments

Comments
 (0)