Tristan Matthews
2014-Apr-15 19:45 UTC
[Speex-dev] [PATCH 2/3] Use fabsf() instead of fabs() since we have floats, not double
On Tue, Apr 15, 2014 at 12:33 PM, Peter Meerwald <pmeerw at pmeerw.net> wrote:> Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net> > --- > libspeexdsp/resample.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/libspeexdsp/resample.c b/libspeexdsp/resample.c > index e32ca45..a19b997 100644 > --- a/libspeexdsp/resample.c > +++ b/libspeexdsp/resample.c > @@ -85,7 +85,7 @@ static void speex_free (void *ptr) {free(ptr);} > #ifdef FIXED_POINT > #define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x))) > #else > -#define WORD2INT(x) ((x) < -32767.5f ? -32768 : ((x) > 32766.5f ? 32767 : > floor(.5+(x)))) > +#define WORD2INT(x) ((x) < -32767.5f ? -32768 : ((x) > 32766.5f ? 32767 : > floorf(.5+(x)))) > #endif > > #define IMAX(a,b) ((a) > (b) ? (a) : (b)) > @@ -273,12 +273,12 @@ static spx_word16_t sinc(float cutoff, float x, int > N, struct FuncDef *window_fu > { > /*fprintf (stderr, "%f ", x);*/ > float xx = x * cutoff; > - if (fabs(x)<1e-6f) > + if (fabsf(x)<1e-6f) > return WORD2INT(32768.*cutoff); > - else if (fabs(x) > .5f*N) > + else if (fabsf(x) > .5f*N) > return 0; > /*FIXME: Can it really be any slower than this? */ > - return WORD2INT(32768.*cutoff*sin(M_PI*xx)/(M_PI*xx) * > compute_func(fabs(2.*x/N), window_func)); > + return WORD2INT(32768.*cutoff*sin(M_PI*xx)/(M_PI*xx) * > compute_func(fabsf(2.*x/N), window_func)); > } > #else > /* The slow way of computing a sinc for the table. Should improve that > some day */ > @@ -286,12 +286,12 @@ static spx_word16_t sinc(float cutoff, float x, int > N, struct FuncDef *window_fu > { > /*fprintf (stderr, "%f ", x);*/ > float xx = x * cutoff; > - if (fabs(x)<1e-6) > + if (fabsf(x)<1e-6f) > return cutoff; > - else if (fabs(x) > .5*N) > + else if (fabsf(x) > .5f*N) > return 0; > /*FIXME: Can it really be any slower than this? */ > - return cutoff*sin(M_PI*xx)/(M_PI*xx) * compute_func(fabs(2.*x/N), > window_func); > + return cutoff*sin(M_PI*xx)/(M_PI*xx) * compute_func(fabsf(2.*x/N), > window_func); > } > #endif >Seems fine, fabsf is supported everywhere fabs is? Best, Tristan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20140415/14518979/attachment.htm
Jean-Marc Valin
2014-Apr-15 20:49 UTC
[Speex-dev] [PATCH 2/3] Use fabsf() instead of fabs() since we have floats, not double
On 15/04/14 03:45 PM, Tristan Matthews wrote:> Seems fine, fabsf is supported everywhere fabs is?No. AFAIK, fabsf() is C99-only, which would be a problem. Jean-Marc
Peter Meerwald
2014-Apr-15 21:36 UTC
[Speex-dev] [PATCH 2/3] Use fabsf() instead of fabs() since we have floats, not double
> > Seems fine, fabsf is supported everywhere fabs is? > > No. AFAIK, fabsf() is C99-only, which would be a problem.right, fabsf() is C99, fabs() is C89 (according to fabs(3) man) I wasn't aware of this constraint; it might be a good idea to enforce/test C89 compliance with "gcc -std=c89" then p. -- Peter Meerwald +43-664-2444418 (mobile)