EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / include / eina_fp.h
1 /* EINA - EFL data type library
2  * Copyright (C) 2007-2008 Jorge Luis Zapata Muga
3  * Copyright (C) 2009 Cedric BAIL
4  *
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.
9  *
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.
14  *
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/>.
18  */
19
20 #ifndef EINA_FP_H_
21 # define EINA_FP_H_
22
23 #include "eina_types.h"
24
25 #ifdef _MSC_VER
26 typedef unsigned __int64 uint64_t;
27 typedef signed __int64   int64_t;
28 typedef signed int       int32_t;
29 #else
30 # include <stdint.h>
31 #endif
32
33 #define EINA_F32P32_PI 0x00000003243f6a89
34
35 typedef int64_t Eina_F32p32;
36 typedef int32_t Eina_F16p16;
37 typedef int32_t Eina_F8p24;
38
39 static inline Eina_F32p32  eina_f32p32_int_from(int32_t v);
40 static inline int32_t      eina_f32p32_int_to(Eina_F32p32 v);
41 static inline Eina_F32p32  eina_f32p32_double_from(double v);
42 static inline double       eina_f32p32_double_to(Eina_F32p32 v);
43
44 static inline Eina_F32p32  eina_f32p32_add(Eina_F32p32 a,
45                                            Eina_F32p32 b);
46 static inline Eina_F32p32  eina_f32p32_sub(Eina_F32p32 a,
47                                            Eina_F32p32 b);
48 static inline Eina_F32p32  eina_f32p32_mul(Eina_F32p32 a,
49                                            Eina_F32p32 b);
50 static inline Eina_F32p32  eina_f32p32_scale(Eina_F32p32 a,
51                                              int         b);
52 static inline Eina_F32p32  eina_f32p32_div(Eina_F32p32 a,
53                                            Eina_F32p32 b);
54 static inline Eina_F32p32  eina_f32p32_sqrt(Eina_F32p32 a);
55 static inline unsigned int eina_f32p32_fracc_get(Eina_F32p32 v);
56
57 // dont use llabs - issues if not on 64bit
58 #define eina_fp32p32_llabs(a) ((a < 0) ? -(a) : (a))
59
60 EAPI Eina_F32p32           eina_f32p32_cos(Eina_F32p32 a);
61 EAPI Eina_F32p32           eina_f32p32_sin(Eina_F32p32 a);
62
63 static inline Eina_F16p16  eina_f16p16_int_from(int32_t v);
64 static inline int32_t      eina_f16p16_int_to(Eina_F16p16 v);
65 static inline Eina_F16p16  eina_f16p16_float_from(float v);
66 static inline float        eina_f16p16_float_to(Eina_F16p16 v);
67
68 static inline Eina_F16p16  eina_f16p16_add(Eina_F16p16 a,
69                                            Eina_F16p16 b);
70 static inline Eina_F16p16  eina_f16p16_sub(Eina_F16p16 a,
71                                            Eina_F16p16 b);
72 static inline Eina_F16p16  eina_f16p16_mul(Eina_F16p16 a,
73                                            Eina_F16p16 b);
74 static inline Eina_F16p16  eina_f16p16_scale(Eina_F16p16 a,
75                                              int         b);
76 static inline Eina_F16p16  eina_f16p16_div(Eina_F16p16 a,
77                                            Eina_F16p16 b);
78 static inline Eina_F16p16  eina_f16p16_sqrt(Eina_F16p16 a);
79 static inline unsigned int eina_f16p16_fracc_get(Eina_F16p16 v);
80
81 static inline Eina_F8p24   eina_f8p24_int_from(int32_t v);
82 static inline int32_t      eina_f8p24_int_to(Eina_F8p24 v);
83 static inline Eina_F8p24   eina_f8p24_float_from(float v);
84 static inline float        eina_f8p24_float_to(Eina_F8p24 v);
85
86 static inline Eina_F8p24   eina_f8p24_add(Eina_F8p24 a,
87                                           Eina_F8p24 b);
88 static inline Eina_F8p24   eina_f8p24_sub(Eina_F8p24 a,
89                                           Eina_F8p24 b);
90 static inline Eina_F8p24   eina_f8p24_mul(Eina_F8p24 a,
91                                           Eina_F8p24 b);
92 static inline Eina_F8p24   eina_f8p24_scale(Eina_F8p24 a,
93                                             int        b);
94 static inline Eina_F8p24   eina_f8p24_div(Eina_F8p24 a,
95                                           Eina_F8p24 b);
96 static inline Eina_F8p24   eina_f8p24_sqrt(Eina_F8p24 a);
97 static inline unsigned int eina_f8p24_fracc_get(Eina_F8p24 v);
98
99 static inline Eina_F32p32  eina_f16p16_to_f32p32(Eina_F16p16 a);
100 static inline Eina_F32p32  eina_f8p24_to_f32p32(Eina_F8p24 a);
101 static inline Eina_F16p16  eina_f32p32_to_f16p16(Eina_F32p32 a);
102 static inline Eina_F16p16  eina_f8p24_to_f16p16(Eina_F8p24 a);
103 static inline Eina_F8p24   eina_f32p32_to_f8p24(Eina_F32p32 a);
104 static inline Eina_F8p24   eina_f16p16_to_f8p24(Eina_F16p16 a);
105
106 #include "eina_inline_f32p32.x"
107 #include "eina_inline_f16p16.x"
108 #include "eina_inline_f8p24.x"
109 #include "eina_inline_fp.x"
110
111 #endif