correct type overflow in im_c2ps/im_abs

This commit is contained in:
John Cupitt 2008-01-09 10:55:28 +00:00
parent 8e7f9e9381
commit 3b80b682a7
2 changed files with 38 additions and 13 deletions

View File

@ -150,6 +150,7 @@ AC_FUNC_MMAP
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand])
AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])])
AC_CHECK_LIB(m,hypot,[AC_DEFINE(HAVE_HYPOT,1,[have hypot() in libm.])])
# have to have these
PKG_CHECK_MODULES(REQUIRED, glib-2.0 >= 2.6 gmodule-2.0 >= 2.4 libxml-2.0 gobject-2.0)

View File

@ -105,19 +105,43 @@
/* Complex abs operation: calculate modulus.
*/
#define complexabs(TYPE)\
{\
TYPE *p = (TYPE *) in;\
TYPE *q = (TYPE *) out;\
\
for( x = 0; x < sz; x++ ) {\
double rp = p[0];\
double ip = p[1];\
\
p += 2;\
q[x] = sqrt( rp * rp + ip * ip );\
}\
}
#ifdef HAVE_HYPOT
#define complexabs(TYPE) { \
TYPE *p = (TYPE *) in; \
TYPE *q = (TYPE *) out; \
TYPE *q_stop = q + sz; \
\
while( q < q_stop ) \
*q++= hypot( *p++, *p++ ); \
}
#else /*HAVE_HYPOT*/
#define complexabs(TYPE) { \
TYPE *p = (TYPE *) in; \
TYPE *q = (TYPE *) out; \
TYPE *q_stop = q + sz; \
\
while( q < q_stop ){ \
double rp = *p++; \
double ip = *p++; \
double abs_rp= fabs( rp ); \
double abs_ip= fabs( ip ); \
\
if( abs_rp > abs_ip ){ \
double temp= ip / rp; \
*q++= abs_rp * sqrt( 1.0 + temp * temp ); \
} \
else { \
double temp= rp / ip; \
*q++= abs_ip * sqrt( 1.0 + temp * temp ); \
} \
} \
}
#endif /*HAVE_HYPOT*/
/* Abs a buffer of PELs.
*/