1 /* EINA - EFL data type library
2 * Copyright (C) 2007-2008 Jorge Luis Zapata Muga
3 * Copyright (C) 2009 Cedric BAIL
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library;
17 * if not, see <http://www.gnu.org/licenses/>.
20 #ifndef EINA_INLINE_F8P24_X_
21 #define EINA_INLINE_F8P24_X_
23 static inline Eina_F8p24
24 eina_f8p24_add(Eina_F8p24 a, Eina_F8p24 b)
29 static inline Eina_F8p24
30 eina_f8p24_sub(Eina_F8p24 a, Eina_F8p24 b)
35 static inline Eina_F8p24
36 eina_f8p24_mul(Eina_F8p24 a, Eina_F8p24 b)
38 return (Eina_F8p24)(((int64_t) a * (int64_t) b) >> 24);
41 static inline Eina_F8p24
42 eina_f8p24_scale(Eina_F8p24 a, int b)
47 static inline Eina_F8p24
48 eina_f8p24_div(Eina_F8p24 a, Eina_F8p24 b)
50 return (Eina_F8p24) ((((int64_t) a) << 24) / (int64_t) b);
53 static inline Eina_F8p24
54 eina_f8p24_sqrt(Eina_F8p24 a)
56 unsigned int root, remHi, remLo, testDiv, count;
58 root = 0; /* Clear root */
59 remHi = 0; /* Clear high part of partial remainder */
60 remLo = a; /* Get argument into low part of partial remainder */
61 count = (23 + (24 >> 1)); /* Load loop counter */
63 remHi = (remHi << 2) | (remLo >> 30);
64 remLo <<= 2; /* get 2 bits of arg */
65 root <<= 1; /* Get ready for the next bit in the root */
66 testDiv = (root << 1) + 1; /* Test radical */
72 } while (count-- != 0);
76 static inline unsigned int
77 eina_f8p24_fracc_get(Eina_F8p24 v)
79 return (v & 0xffffff);