Fixed Point Arithmetic  0
Fixed-point math library.
fixed_point.h
Go to the documentation of this file.
1 
43 #ifndef FIXED_POINT_H
44 #define FIXED_POINT_H
45 
46 #include <stdbool.h>
47 #include "common.h"
48 #include "types.h"
49 
64 #define FXP_VALUE_OP(name, typeR, typeAB, op) \
65 FXP_DECLARATION(typeR name(typeAB a, typeAB b)) \
66 { \
67  return a.v op b.v; \
68 }
69 
81 #define FXP_OP2(name, typeR, typeA, typeB, op) \
82 FXP_DECLARATION(typeR name(typeA a, typeB b)) \
83 { \
84  typeR r = {a.v op b.v}; \
85  return r; \
86 }
87 
97 #define FXP_OP3(name, typeRAB, op) FXP_OP2(name, typeRAB, typeRAB, typeRAB, op)
98 
107 #define FXP_SCMP(name, op) FXP_VALUE_OP(name, bool, frac, op)
108 
117 #define FXP_DCMP(name, op) FXP_VALUE_OP(name, bool, dfrac, op)
118 
131 #define F_SIGN(a) (((a).v >= 0)? 1 : -1)
132 
136 #ifdef FXP_C99_INLINE
137 
138 #ifndef _FXP_INLINE_KW
139 #define _FXP_INLINE_KW inline
140 #define _FXP_INLINE_PROTO_KW extern inline
141 #endif
142 
143 #ifndef FXP_DECLARATION
144 #define FXP_DECLARATION FXP_DECLARATION_C99_HEADER
145 #endif
146 
147 #include "inline/fixed_point.h"
148 
149 #endif /* FXP_C99_INLINE */
150 
151 #endif /* FIXED_POINT_H */
Type definitions for fixed point arithmetic types.