[xf86-input-joystick] Silence clang warnings on floating point abs() / pow() calls.

Submitted by Matthieu Herrb on Feb. 10, 2019, 4:15 p.m.

Details

Message ID 20190210161500.38513-1-matthieu@herrb.eu
State New
Series "Silence clang warnings on floating point abs() / pow() calls."
Headers show

Commit Message

Matthieu Herrb Feb. 10, 2019, 4:15 p.m.
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
---
 src/jstk_axis.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/jstk_axis.c b/src/jstk_axis.c
index cb4a004..37bb66b 100644
--- a/src/jstk_axis.c
+++ b/src/jstk_axis.c
@@ -136,11 +136,11 @@  jstkAxisTimer(OsTimerPtr        timer,
 	     */
 
             /* How many pixels should this axis move the cursor */
-            p1 = (pow((abs((float)axis->value) - (float)axis->deadzone) *
+            p1 = (powf((fabsf((float)axis->value) - (float)axis->deadzone) *
                   scale / 23, 1.4f) + 100.0f) *
                  ((float)NEXTTIMER / 40000.0f);
             /* How many "pixels" should this axis scroll */
-            p2 = ((pow((abs((float)axis->value) - (float)axis->deadzone) *
+            p2 = ((powf((fabsf((float)axis->value) - (float)axis->deadzone) *
                   scale / 1000.0f, 2.5f)) + 200.0f) *
                  ((float)NEXTTIMER / 200000.0f);
         } else if (axis->type == JSTK_TYPE_ACCELERATED) {

Comments

Walter Harms Feb. 10, 2019, 5:42 p.m.
> Matthieu Herrb <matthieu@herrb.eu> hat am 10. Februar 2019 um 17:15
> geschrieben:
> 
> 
> Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
> ---
>  src/jstk_axis.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/jstk_axis.c b/src/jstk_axis.c
> index cb4a004..37bb66b 100644
> --- a/src/jstk_axis.c
> +++ b/src/jstk_axis.c
> @@ -136,11 +136,11 @@ jstkAxisTimer(OsTimerPtr        timer,
>  	     */
>  
>              /* How many pixels should this axis move the cursor */
> -            p1 = (pow((abs((float)axis->value) - (float)axis->deadzone) *
> +            p1 = (powf((fabsf((float)axis->value) - (float)axis->deadzone) *
>                    scale / 23, 1.4f) + 100.0f) *
>                   ((float)NEXTTIMER / 40000.0f);

look reasonable perhaps we can improve readability also, like:
     double delta=fabsf(axis->value) - axis->deadzone;
     double ftimer=(float)NEXTTIMER / 40000.0f;

     p1= powf(delta/23.0*scale,1.4f)/ftimer+100.0f/ftimer;


>              /* How many "pixels" should this axis scroll */
> -            p2 = ((pow((abs((float)axis->value) - (float)axis->deadzone) *

               ftimer=(float)NEXTTIMER / 200000.0f;
               p2= powf(delta/1000.0*scale,2.5f)/ftimer+200.0f/ftimer;
you can earn bonus points for explaining the magic numbers.

just my 2 cents,
   re,
    wh
                 
> +            p2 = ((powf((fabsf((float)axis->value) - (float)axis->deadzone) *
>                    scale / 1000.0f, 2.5f)) + 200.0f) *
>                   ((float)NEXTTIMER / 200000.0f);
>          } else if (axis->type == JSTK_TYPE_ACCELERATED) {
> -- 
> 2.20.1
> 
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel