From 2134d1bdb81e4959560d5becea06c43c083a9811 Mon Sep 17 00:00:00 2001 From: Mohammed Suhail Munshi Date: Tue, 8 Feb 2022 15:23:00 +0000 Subject: Int32 to Float32 implicit casting fix - Int32 is cast to Float32 implicitly during range checking comparisons, value may change due to float32 range limitations. - Fixed by casting float32 var to double64 before comparisons. - This issue prevented NDK r23b compilation Resolves: [COMPMID-5051] Change-Id: I1695f9ad5fa147d81cbcfda9e0152aefab960c82 Signed-off-by: Mohammed Suhail Munshi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7093 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Sheri Zhang --- arm_compute/core/Utils.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'arm_compute/core/Utils.h') diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h index b24955d778..a279ef310a 100644 --- a/arm_compute/core/Utils.h +++ b/arm_compute/core/Utils.h @@ -1156,13 +1156,15 @@ bool check_value_range(T val, DataType dt, QuantizationInfo qinfo = Quantization } case DataType::U32: { + const auto val_d64 = static_cast(val); const auto val_u32 = static_cast(val); - return ((val_u32 == val) && val >= std::numeric_limits::lowest() && val <= std::numeric_limits::max()); + return ((val_u32 == val_d64) && val_d64 >= std::numeric_limits::lowest() && val_d64 <= std::numeric_limits::max()); } case DataType::S32: { + const auto val_d64 = static_cast(val); const auto val_s32 = static_cast(val); - return ((val_s32 == val) && val >= std::numeric_limits::lowest() && val <= std::numeric_limits::max()); + return ((val_s32 == val_d64) && val_d64 >= std::numeric_limits::lowest() && val_d64 <= std::numeric_limits::max()); } case DataType::BFLOAT16: return (val >= bfloat16::lowest() && val <= bfloat16::max()); -- cgit v1.2.1