diff --git a/Docs/ChangeLog-5x.md b/Docs/ChangeLog-5x.md index eedf9c46..f8173a83 100644 --- a/Docs/ChangeLog-5x.md +++ b/Docs/ChangeLog-5x.md @@ -17,6 +17,8 @@ The 5.5.0 release is a minor maintenance release. * **Bug fix:** Add missing low-clamp when storing decompressed HDR data into a UNORM8 image. Prior to this fix, output colors would be incorrect if a HDR void-extent block contained a negative FP16 color value. + * **Bug fix:** Avoid undefined NaN to int conversion behavior that is + triggered by NaNs generated by atan2() calls where both inputs are zero. ## 5.4.0 diff --git a/Source/astcenc_weight_align.cpp b/Source/astcenc_weight_align.cpp index e961b3c2..249fbf8d 100644 --- a/Source/astcenc_weight_align.cpp +++ b/Source/astcenc_weight_align.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- -// Copyright 2011-2025 Arm Limited +// Copyright 2011-2026 Arm Limited // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy @@ -130,6 +130,10 @@ static void compute_angular_offsets( } vfloat angle = atan2(anglesum_y, anglesum_x); + + // Suppress NaNs generated if anglesums are both zero + angle = select(vfloat::zero(), angle, angle == angle); + vfloat ofs = angle * mult; storea(ofs, offsets + i); }