ARM-software / CMSIS-DSP

CMSIS-DSP embedded compute library for Cortex-M and Cortex-A
https://arm-software.github.io/CMSIS-DSP
Apache License 2.0
454 stars 122 forks source link

GCC compiler warning in arm_divide_q15() #159

Closed felixvanoost closed 4 months ago

felixvanoost commented 4 months ago

When compiling CMSIS-DSP using GCC 10.3, the compiler produces the following warning in arm_divide_q15():

[build] Source/FastMathFunctions/arm_divide_q15.c: In function 'arm_divide_q15':
[build] Source/FastMathFunctions/arm_divide_q15.c:77:21: error: overflow in conversion from 'int' to 'q15_t' {aka 'short int'} changes value from '32768' to '-32768' [-Werror=overflow]
[build]    77 |         *quotient = 0x8000;
[build]       |                     ^~~~~~

0x8000 represents the positive integer 32768, but what was actually intended by the writer is the two's complement representation of -32768. Replacing 0x8000 with -32768 resolves the compiler warning and avoids further ambiguity.

christophe0606 commented 4 months ago

@felixvanoost Thanks. I'll pass a few regression tests and I'll merge the PR.