1 /*
2 common.h - Blah. Some stuff
3
4 Copyright (C) 2002 Mike Rawes
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef blop_common_h
22 #define blop_common_h
23
24 #include "math_func.h"
25
26 /* Handy constants and macros */
27
28 /*
29 * Smallest generated non-zero float
30 * Used for pre-empting denormal numbers
31 */
32 #ifndef SMALLEST_FLOAT
33 #define SMALLEST_FLOAT (1.0 / (float)0xFFFFFFFF)
34 #endif
35
36 /*
37 * Clip without branch (from http://musicdsp.org)
38 */
39
40 static inline float
f_min(float x,float a)41 f_min (float x, float a)
42 {
43 return a - (a - x + FABSF (a - x)) * 0.5f;
44 }
45 static inline float
f_max(float x,float b)46 f_max (float x, float b)
47 {
48 return (x - b + FABSF (x - b)) * 0.5f + b;
49 }
50 static inline float
f_clip(float x,float a,float b)51 f_clip (float x, float a, float b)
52 {
53 return 0.5f * (FABSF (x - a) + a + b - FABSF (x - b));
54 }
55
56 #endif /* blop_common_h */
57