[igt-dev] [PATCH igt] lib/audio: Replace sqrt(a*a + b*b) with hypot(a, b)

Chris Wilson chris at chris-wilson.co.uk
Mon Mar 12 15:47:59 UTC 2018


Quoting Chris Wilson (2018-03-12 15:43:50)
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  lib/igt_audio.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/lib/igt_audio.c b/lib/igt_audio.c
> index 2321d1c6..229ce6c6 100644
> --- a/lib/igt_audio.c
> +++ b/lib/igt_audio.c
> @@ -266,9 +266,7 @@ bool audio_signal_detect(struct audio_signal *signal, int channels,
>                 max = 0;
>  
>                 for (i = 0; i < frames / 2; i++) {
> -                       amplitude[i] = sqrt(data[i] * data[i] +
> -                                           data[frames - i] *
> -                                           data[frames - i]);
> +                       amplitude[i] = hypot(data[i], data[frames - i]);
>                         if (amplitude[i] > max)
>                                 max = amplitude[i];

Although the sqrt is overkill as the code would be just as happy using
amplitude squared. Ok, the code is quite weird, I'm not going to read
any more...
-Chris


More information about the igt-dev mailing list