1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 22:28:02 +01:00

Use single-precision math functions when available

Since C99 we have floating point functions available for single precision,
so as it is what we need we detect them (configure) and use them when
appropriate. The goal is to avoid unnecessary float->double + double->float
conversion.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2015-05-24 15:49:08 +02:00
committed by Carlos R. Mafra
parent d28edde23e
commit 9ab2203456
2 changed files with 51 additions and 14 deletions

View File

@@ -50,5 +50,35 @@ AS_IF([test "x$wm_cv_libm_pi" = "xno"],
[Defines how to access the value of Pi])
AS_IF([test "x$wm_cv_libm_pi" != "xyes"],
[CFLAGS="$CFLAGS $wm_cv_libm_pi"]) ])
AC_CACHE_CHECK([if sinf+cosf are defined in math.h], [wm_cv_libm_sinf],
[wm_cv_libm_sinf="no"
wm_save_CFLAGS="$CFLAGS"
wm_save_LIBS="$LIBS"
LIBS="$LIBS $LIBM"
for wm_arg in dnl
"% yes" dnl natively available (C99 compliant)
"-D_XOPEN_SOURCE=600" ; dnl Explicit request
do
CFLAGS="$wm_save_CFLAGS `echo "$wm_arg" | sed -e 's, *%.*$,,' `"
AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
@%:@include <math.h>
], [dnl
float a, b;
a = WM_PI;
b = sqrtf(a);
a = atan2f(a, b);
b = cosf(a);
a = sinf(b);
return (int)a;])],
[wm_cv_libm_sinf="`echo "$wm_arg" | sed -e 's,^.*% *,,' `" ; break])
done
LIBS="$wm_save_LIBS"
CFLAGS="$wm_save_CFLAGS"])
AS_IF([test "x$wm_cv_libm_sinf" != "xno"],
[AC_DEFINE([HAVE_FLOAT_MATHFUNC], [1],
[Defined if the 'float'-typed math function are available (sinf, cosf)])
AS_IF([test "x$wm_cv_libm_sinf" != "xyes"],
[CFLAGS="$CFLAGS $wm_cd_libm_sinf"]) ])
AC_SUBST(LIBM) dnl
])

View File

@@ -52,6 +52,13 @@
#include "event.h"
#ifndef HAVE_FLOAT_MATHFUNC
#define sinf(x) ((float)sin((double)(x)))
#define cosf(x) ((float)cos((double)(x)))
#define sqrtf(x) ((float)sqrt((double)(x)))
#define atan2f(y, x) ((float)atan((double)(y) / (double)(x)))
#endif
static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
unsigned int *new_width, unsigned int *new_height);
static void save_old_geometry(WWindow *wwin, int directions);
@@ -792,8 +799,8 @@ static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx,
if (angle > final_angle)
angle = final_angle;
dx = (cw / 10) - ((cw / 5) * sin(angle));
dch = (ch / 2) * cos(angle);
dx = (cw / 10) - ((cw / 5) * sinf(angle));
dch = (ch / 2) * cosf(angle);
midy = cy + (ch / 2);
points[0].x = cx + dx;
@@ -857,19 +864,19 @@ animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int
if (angle > final_angle)
angle = final_angle;
a = atan(ch / cw);
d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
a = atan2f(ch, cw);
d = sqrtf((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
points[0].x = cx + cos(angle - a) * d;
points[0].y = cy + sin(angle - a) * d;
points[1].x = cx + cos(angle + a) * d;
points[1].y = cy + sin(angle + a) * d;
points[2].x = cx + cos(angle - a + WM_PI) * d;
points[2].y = cy + sin(angle - a + WM_PI) * d;
points[3].x = cx + cos(angle + a + WM_PI) * d;
points[3].y = cy + sin(angle + a + WM_PI) * d;
points[4].x = cx + cos(angle - a) * d;
points[4].y = cy + sin(angle - a) * d;
points[0].x = cx + cosf(angle - a) * d;
points[0].y = cy + sinf(angle - a) * d;
points[1].x = cx + cosf(angle + a) * d;
points[1].y = cy + sinf(angle + a) * d;
points[2].x = cx + cosf(angle - a + (float)WM_PI) * d;
points[2].y = cy + sinf(angle - a + (float)WM_PI) * d;
points[3].x = cx + cosf(angle + a + (float)WM_PI) * d;
points[3].y = cy + sinf(angle + a + (float)WM_PI) * d;
points[4].x = cx + cosf(angle - a) * d;
points[4].y = cy + sinf(angle - a) * d;
XGrabServer(dpy);
XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
XFlush(dpy);