Use C++-style casts (#1576)

This commit is contained in:
Sylvie
2024-12-09 21:56:54 -05:00
committed by GitHub
parent e66da4c8c7
commit b877c81c32
33 changed files with 197 additions and 173 deletions

View File

@@ -48,7 +48,7 @@ int32_t op_shift_left(int32_t value, int32_t amount) {
// Use unsigned to force a bitwise shift
// Casting back is OK because the types implement two's complement behavior
return (uint32_t)value << amount;
return static_cast<uint32_t>(value) << amount;
}
int32_t op_shift_right(int32_t value, int32_t amount) {
@@ -63,7 +63,7 @@ int32_t op_shift_right(int32_t value, int32_t amount) {
return op_shift_left(value, -amount);
if (value > 0)
return (uint32_t)value >> amount;
return static_cast<uint32_t>(value) >> amount;
// Calculate an OR mask for sign extension
// 1->0x80000000, 2->0xC0000000, ..., 31->0xFFFFFFFE
@@ -71,7 +71,7 @@ int32_t op_shift_right(int32_t value, int32_t amount) {
// The C++ standard leaves shifting right negative values
// undefined, so use a left shift manually sign-extended
return ((uint32_t)value >> amount) | amount_high_bits;
return (static_cast<uint32_t>(value) >> amount) | amount_high_bits;
}
int32_t op_shift_right_unsigned(int32_t value, int32_t amount) {
@@ -83,5 +83,5 @@ int32_t op_shift_right_unsigned(int32_t value, int32_t amount) {
if (amount < 0)
return op_shift_left(value, -amount);
return (uint32_t)value >> amount;
return static_cast<uint32_t>(value) >> amount;
}