3 * The olsr.org Optimized Link-State Routing daemon(olsrd)
4 * Copyright (c) 2008, Sven-Ola Tuecke (sven-ola@gmx.de)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of olsr.org, olsrd nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * Visit http://www.olsr.org for more information.
36 * If you find this software useful feel free to make a donation
37 * to the project. For more information see the website or contact
38 * the copyright holders.
50 * Use this to find implicit number conversions when compiling
51 * Note: comparing pointers is unsigned, so do not use to run.
54 typedef signed long sfpm;
55 typedef unsigned long ufpm;
61 * Use this for extra long 64 bit calculations
63 typedef long long fpm;
64 typedef signed long long sfpm;
65 typedef unsigned long long ufpm;
71 * The standard math should function with only 32 bits
74 typedef signed long sfpm;
75 typedef unsigned long ufpm;
80 #define FPM_NUM (1 << FPM_BIT)
81 #define FPM_MSK (FPM_NUM - 1)
82 #define FPM_MAX ((sfpm)(~(ufpm)0 >> 1) >> FPM_BIT)
83 #define FPM_MIN ((sfpm)-1 - FPM_MAX)
84 #define FPM_INT_MAX ((sfpm)(~(ufpm)0 >> 1))
85 #define FPM_INT_MIN ((sfpm)-1 - FPM_INT_MAX)
87 #define itofpm_def(a) (fpm)((sfpm)((a) << FPM_BIT))
88 #define ftofpm_def(a) (fpm)((sfpm)((a) * FPM_NUM))
89 #define fpmtoi_def(a) (int)((sfpm)(a) >> FPM_BIT)
90 #define fpmtof_def(a) ((float)(sfpm)(a) / FPM_NUM)
92 #define fpmadd_def(a, b) (fpm)((sfpm)(a) + (sfpm)(b))
93 #define fpmsub_def(a, b) (fpm)((sfpm)(a) - (sfpm)(b))
94 #define fpmmul_def(a, b) (fpm)(((sfpm)(a) * (sfpm)(b)) >> FPM_BIT)
95 #define fpmdiv_def(a, b) (fpm)(((sfpm)(a) << FPM_BIT) / (sfpm)(b))
98 * Special: first or second factor is an integer
100 #define fpmimul_def(a, b) (fpm)((int)(a) * (sfpm)(b))
101 #define fpmmuli_def(a, b) (fpm)((sfpm)(a) * (int)(b))
104 * Special: divisor is an integer
106 #define fpmidiv_def(a, b) (fpm)((sfpm)(a) / (int)(b))
111 * Special: uses long long for larger numbers, currently unused
113 #define fpmlmul_def(a, b) (sfpm)(((long long)(a) * (b)) >> FPM_BIT)
114 #define fpmldiv_def(a, b) (sfpm)(((long long)(a) << FPM_BIT) / (b))
119 #define itofpm itofpm_def
120 #define ftofpm ftofpm_def
121 #define fpmtoi fpmtoi_def
122 #define fpmtof fpmtof_def
124 #define fpmadd fpmadd_def
125 #define fpmsub fpmsub_def
126 #define fpmmul fpmmul_def
127 #define fpmdiv fpmdiv_def
128 #define fpmimul fpmimul_def
129 #define fpmmuli fpmmuli_def
130 #define fpmidiv fpmidiv_def
133 #define fpmlmul fpmlmul_def
134 #define fpmldiv fpmldiv_def
144 fpm fpmadd(fpm a, fpm b);
145 fpm fpmsub(fpm a, fpm b);
146 fpm fpmmul(fpm a, fpm b);
147 fpm fpmdiv(fpm a, fpm b);
148 fpm fpmimul(int a, fpm b);
149 fpm fpmmuli(fpm a, int b);
150 fpm fpmidiv(fpm a, int b);
153 fpm fpmlmul(fpm a, fpm b);
154 fpm fpmldiv(fpm a, fpm b);
159 #define INFINITE_ETX itofpm(FPM_MAX)
160 #define MIN_LINK_QUALITY ftofpm(0.01)
161 #define ZERO_ETX itofpm(0)
162 #define CEIL_LQDIFF ftofpm(1.1)
163 #define FLOOR_LQDIFF ftofpm(0.9)
165 fpm atofpm(const char *);
166 const char *fpmtoa(fpm);
170 #define INFINITE_ETX ((float)(1 << 30))
172 #define MIN_LINK_QUALITY 0.01
173 #define CEIL_LQDIFF 1.1
174 #define FLOOR_LQDIFF 0.9
176 float atofpm(const char *);
177 const char *fpmtoa(float);
186 * indent-tabs-mode: nil