Skip to content

Commit

Permalink
Use IndexOfAnyExcept in BigInteger.IsPowerOfTwo (#104513)
Browse files Browse the repository at this point in the history
* Use IndexOfAnyExcept in BigInteger.IsPowerOfTwo

* Use ContainsAnyExcept
  • Loading branch information
Rob-Hague authored Jul 9, 2024
1 parent 01dbf51 commit ce2f85b
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,10 @@ public bool IsPowerOfTwo

if (_sign != 1)
return false;

int iu = _bits.Length - 1;
if (!BitOperations.IsPow2(_bits[iu]))
return false;
while (--iu >= 0)
{
if (_bits[iu] != 0)
return false;
}
return true;

return BitOperations.IsPow2(_bits[iu]) && !_bits.AsSpan(0, iu).ContainsAnyExcept(0u);
}
}

Expand Down

0 comments on commit ce2f85b

Please sign in to comment.