Add more array helper functions, add U64 to I64 saturate cast

This commit is contained in:
doylet
2024-02-02 00:08:31 +11:00
parent 105ee9f4b1
commit f6c836ba84
3 changed files with 68 additions and 22 deletions
+7 -4
View File
@@ -585,16 +585,19 @@ DQN_API uint64_t Dqn_Safe_SaturateCastUSizeToU64(Dqn_usize val)
return result;
}
// NOTE: Dqn_Safe_SaturateCastU64To*
// -----------------------------------------------------------------------------
// INT*_MAX literals will be promoted to the type of val as val is
// the highest possible rank (unsigned > signed).
// NOTE: Dqn_Safe_SaturateCastU64To* ///////////////////////////////////////////////////////////////
DQN_API int Dqn_Safe_SaturateCastU64ToInt(uint64_t val)
{
int result = DQN_CHECK(val <= INT_MAX) ? DQN_CAST(int)val : INT_MAX;
return result;
}
DQN_API int64_t Dqn_Safe_SaturateCastU64ToI64(uint64_t val)
{
int64_t result = DQN_CHECK(val <= INT64_MAX) ? DQN_CAST(int64_t)val : INT64_MAX;
return result;
}
// Both operands are unsigned and the lowest rank operand will be promoted to
// match the highest rank operand.
DQN_API unsigned int Dqn_Safe_SaturateCastU64ToUInt(uint64_t val)