From 6b1e28a60e74050a965a55edbac8d6b96ea5ff9b Mon Sep 17 00:00:00 2001 From: musil Date: Fri, 6 Mar 2015 17:49:08 +0000 Subject: update squareroot to millers q8_sqrt svn path=/trunk/externals/iem/iem_tab/; revision=17436 --- src/tab_sqrt.c | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/tab_sqrt.c b/src/tab_sqrt.c index 29f8889..fca7263 100644 --- a/src/tab_sqrt.c +++ b/src/tab_sqrt.c @@ -8,8 +8,7 @@ iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2009 #include "iem_tab.h" #include -#define TABDUMTAB1SIZE 256 -#define TABDUMTAB2SIZE 1024 + /* -------------------------- tab_sqrt ------------------------------ */ /* x_beg_mem_dst[i] = sqrt(x_beg_mem_src1[i]) */ @@ -28,28 +27,6 @@ typedef struct _tab_sqrt } t_tab_sqrt; static t_class *tab_sqrt_class; -static t_float tab_rsqrt_exptab[TABDUMTAB1SIZE], tab_rsqrt_mantissatab[TABDUMTAB2SIZE]; - -static void init_tab_rsqrt(void) -{ - int i; - - for (i=0; i> 23) & 0xff] * tab_rsqrt_mantissatab[(l >> 13) & 0x3ff]; - - iemarray_setfloat(vec_dst, i, f*g*(1.5f - 0.5f * g * g * f)); +#if ((defined PD_MAJOR_VERSION && defined PD_MINOR_VERSION) && (PD_MAJOR_VERSION > 0 || PD_MINOR_VERSION > 43)) + t_float g = q8_rsqrt(f); + + iemarray_setfloat(vec_dst, i, f*g*(1.5f - 0.5f * g * g * f)); +#else + iemarray_setfloat(vec_dst, i, sqrt(f)); +#endif } } outlet_bang(x->x_obj.ob_outlet); @@ -135,19 +115,22 @@ static void tab_sqrt_list(t_tab_sqrt *x, t_symbol *s, int argc, t_atom *argv) if(n) { t_garray *a; - - for(i=0; i> 23) & 0xff] * tab_rsqrt_mantissatab[(l >> 13) & 0x3ff]; +#if ((defined PD_MAJOR_VERSION && defined PD_MINOR_VERSION) && (PD_MAJOR_VERSION > 0 || PD_MINOR_VERSION > 43)) + t_float g = q8_rsqrt(f); iemarray_setfloat(vec_dst, i, f*g*(1.5f - 0.5f * g * g * f)); +#else + iemarray_setfloat(vec_dst, i, sqrt(f)); +#endif } } outlet_bang(x->x_obj.ob_outlet); @@ -200,7 +183,6 @@ static void *tab_sqrt_new(t_symbol *s, int argc, t_atom *argv) void tab_sqrt_setup(void) { - init_tab_rsqrt(); tab_sqrt_class = class_new(gensym("tab_sqrt"), (t_newmethod)tab_sqrt_new, (t_method)tab_sqrt_free, sizeof(t_tab_sqrt), 0, A_GIMME, 0); class_addbang(tab_sqrt_class, (t_method)tab_sqrt_bang); @@ -208,5 +190,4 @@ void tab_sqrt_setup(void) class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_src, gensym("src"), A_DEFSYMBOL, 0); class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_src, gensym("src1"), A_DEFSYMBOL, 0); class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_dst, gensym("dst"), A_DEFSYMBOL, 0); -// class_sethelpsymbol(tab_sqrt_class, gensym("iemhelp2/tab_sqrt-help")); } -- cgit v1.2.1