diff options
Diffstat (limited to 'modules++/DSPI.h')
-rw-r--r-- | modules++/DSPI.h | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/modules++/DSPI.h b/modules++/DSPI.h index d9e2acf..283e848 100644 --- a/modules++/DSPI.h +++ b/modules++/DSPI.h @@ -1,3 +1,6 @@ + +#include "m_pd.h" + #ifndef DSPI_h #define DSPI_h @@ -7,10 +10,60 @@ // test if floating point number is denormal -#define DSPI_IS_DENORMAL(f) (((*(unsigned int *)&(f))&0x7f800000) == 0) + +#if defined(__i386__) || defined(__x86_64__) // Type punning code: + +#if PD_FLOAT_PRECISION == 32 + +typedef union +{ + unsigned int i; + t_float f; +} t_dspiflint; + +static inline int DSPI_IS_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7f800000) == 0); +} // test if almost denormal, choose whichever is fastest -#define DSPI_IS_ALMOST_DENORMAL(f) (((*(unsigned int *)&(f))&0x7f800000) < 0x08000000) +static inline int DSPI_IS_ALMOST_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7f800000) < 0x08000000); +} + +#elif PD_FLOAT_PRECISION == 64 + +typedef union +{ + unsigned int i[2]; + t_float f; +} t_dspiflint; + +static inline int DSPI_IS_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7ff00000) == 0); +} + +static inline int DSPI_IS_ALMOST_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7ff00000) < 0x10000000); +} + +#endif // endif PD_FLOAT_PRECISION +#else // if not defined(__i386__) || defined(__x86_64__) +#define DSPI_IS_DENORMAL(f) 0 +#endif // end if defined(__i386__) || defined(__x86_64__) + + //#define DSPI_IS_ALMOST_DENORMAL(f) (fabs(f) < 3.e-34) -#endif +#endif // end ifndef DSPI_h |