Skip to content

Commit

Permalink
Ensure the IBinaryInteger.RotateLeft/Right DIMs use unsigned right sh…
Browse files Browse the repository at this point in the history
…ift (#98119)

* Adding tests covering DIMs for signed and unsigned binary integers

* Ensure the IBinaryInteger.RotateLeft/Right DIMs use unsigned right shift
  • Loading branch information
tannergooding authored Feb 8, 2024
1 parent edf4ae8 commit 9367edc
Show file tree
Hide file tree
Showing 2 changed files with 400 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static virtual TSelf RotateLeft(TSelf value, int rotateAmount)
}

int bitCount = checked(value!.GetByteCount() * 8);
return (value << rotateAmount) | (value >> (bitCount - rotateAmount));
return (value << rotateAmount) | (value >>> (bitCount - rotateAmount));
}

/// <summary>Rotates a value right by a given amount.</summary>
Expand All @@ -158,7 +158,7 @@ static virtual TSelf RotateRight(TSelf value, int rotateAmount)
}

int bitCount = checked(value!.GetByteCount() * 8);
return (value >> rotateAmount) | (value << (bitCount - rotateAmount));
return (value >>> rotateAmount) | (value << (bitCount - rotateAmount));
}

/// <summary>Computes the number of trailing zero bits in a value.</summary>
Expand Down
Loading

0 comments on commit 9367edc

Please sign in to comment.