aboutsummaryrefslogtreecommitdiff
path: root/modules++/DSPI.h
diff options
context:
space:
mode:
authorKatja <katjav@users.sourceforge.net>2011-11-06 14:41:44 +0000
committerKatja <katjav@users.sourceforge.net>2011-11-06 14:41:44 +0000
commit4f1ee28d687d583601d41ff58e1618b381d2675f (patch)
treeeb9df33c9928ec11de287a1d70ec714c9a3b9f7c /modules++/DSPI.h
parent4a05094c9a009707674c079c0481eaf8e1f8490f (diff)
made creb compliant with double precision
- changed float to t_float - adapted subnormal detection svn path=/trunk/externals/creb/; revision=15706
Diffstat (limited to 'modules++/DSPI.h')
-rw-r--r--modules++/DSPI.h59
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