aboutsummaryrefslogtreecommitdiff
path: root/modules++/DSPI.h
blob: 4bbfa82fe8bbf9de404a10ae7fcb4b2484b0c09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

#include "m_pd.h"

#ifndef DSPI_h
#define DSPI_h

#define DSPImin(x,y)			(((x)<(y)) ? (x) : (y))
#define DSPImax(x,y)			(((x)>(y)) ? (x) : (y))
#define DSPIclip(min, x, max)	(DSPImin(DSPImax((min), (x)), max))


// test if floating point number is denormal

#if defined(__i386__) || defined(__x86_64__) // Type punning code:

#ifndef PD_FLOAT_PRECISION
#define PD_FLOAT_PRECISION 32
#endif

#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 & 0x7f800000) == 0);
}

// test if almost denormal, choose whichever is fastest
static inline int DSPI_IS_ALMOST_DENORMAL(t_float f) 
{
    t_dspiflint pun;
    pun.f = f;
    return ((pun.i & 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 // end ifndef DSPI_h