nouveau.hidd: disable warnings about not initialized variables
[AROS.git] / workbench / classes / gadgets / colorwheel / fixmath.h
blob135cbb1035160ae583f155bd0702f89c986b7c84
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef FIXMATH_H
7 #define FIXMATH_H
9 #ifndef EXEC_TYPES_H
10 # include <exec/types.h>
11 #endif
13 /****************************************************************************/
15 #define FIXED_ONE INT_TO_FIXED(1)
16 #define FIXED_PI 205887L
17 #define FIXED_2PI 411775L
18 #define FIXED_E 178144L
19 #define FIXED_ROOT2 74804L
20 #define FIXED_ROOT3 113512L
21 #define FIXED_GOLDEN 106039L
23 #define INT_TO_FIXED(x) ((x) << 16)
24 #define DOUBLE_TO_FIXED(x) ((Fixed32)(x * 65536.0 + 0.5))
25 #define FIXED_TO_INT(x) ((x) >> 16)
26 #define FIXED_TO_DOUBLE(x) (((double)x) / 65536.0)
27 #define ROUND_FIXED_TO_INT(x) (((x) + 0x8000) >> 16)
29 #define ANG90 (FIXED_PI/2)
30 #define ANG180 (FIXED_PI)
31 #define ANG270 (ANG180+ANG90)
32 #define ANG360 (FIXED_2PI)
34 /****************************************************************************/
36 typedef LONG Fixed32;
38 Fixed32 FixSqrt( Fixed32 );
39 Fixed32 FixSqrti(ULONG x);
40 //Fixed32 FixSinCos( Fixed32 theta, Fixed32 *sinus );
41 Fixed32 FixAtan2( Fixed32, Fixed32 );
43 /****************************************************************************/
45 __inline static Fixed32 FixMul(Fixed32 eins,Fixed32 zwei)
47 #ifdef __AROS__
48 QUAD result = (QUAD)eins * (QUAD)zwei;
49 eins = result >> 16;
50 #else
52 #ifndef version060
54 __asm __volatile
55 ("muls.l %1,%1:%0 \n\t"
56 "move %1,%0 \n\t"
57 "swap %0 "
59 : "=d" (eins), "=d" (zwei)
60 : "0" (eins), "1" (zwei)
63 #else
64 #if 0
65 __asm __volatile
66 ("fmove.l %0,fp0 \n\t"
67 "fmul.l %2,fp0 \n\t"
68 "fmul.s #$37800000,fp0 \n\t"
70 /* "fintrz.x fp0,fp0 \n\t"*/
71 "fmove.l fp0,%0"
73 : "=d" (eins)
74 : "0" (eins), "d" (zwei)
75 : "fp0"
77 #else
78 eins = (Fixed32) ( (double) eins * (double) zwei * 0.0000152587890625 );
79 #endif
81 #endif /* version060 */
83 #endif /* __AROS__ */
85 return eins;
88 /****************************************************************************/
90 __inline static Fixed32 FixDiv(Fixed32 eins,Fixed32 zwei)
92 #ifdef __AROS__
93 QUAD result = ((QUAD)eins << 16) / (QUAD)zwei;
94 eins = (Fixed32) result;
95 #else
97 #ifndef version060
98 __asm __volatile
99 ("swap %0\n\t"
100 "move.w %0,d2\n\t"
101 "ext.l d2\n\t"
102 "clr.w %0\n\t"
103 "divs.l %1,d2:%0\n\t"
105 : "=d" (eins), "=d" (zwei)
106 : "0" (eins), "1" (zwei)
107 : "d2"
109 #else
110 #if 0
111 __asm __volatile
112 ("fmove.l %0,fp0 \n\t"
113 "fdiv.l %2,fp0 \n\t"
114 "fmul.s #$47800000,fp0 \n\t"
116 /* "fintrz.x fp0 \n\t"*/
117 "fmove.l fp0,%0"
119 : "=d" (eins)
120 : "0" (eins), "d" (zwei)
121 : "fp0"
123 #else
124 eins = (double) eins / (double) zwei * 65536.0;
125 #endif
126 #endif /* version060 */
128 #endif /* __AROS__ */
130 return eins;
133 /****************************************************************************/
135 __inline static LONG FixSqr( Fixed32 a )
137 // a = INT_TO_FIXED(a);
138 // return a * a;
139 return FixMul( a, a );
142 /****************************************************************************/
144 __inline static Fixed32 FixSinCos( Fixed32 theta, Fixed32 *sinus )
146 #define MAX_TRIG 1024
147 extern Fixed32 SinCosTab[];
149 theta = FIXED_TO_INT( FixMul( theta << 9, 20861 ) );
150 theta &= (MAX_TRIG - 1);
152 *sinus = SinCosTab[theta];
154 if( ( theta += 256 ) >= MAX_TRIG )
155 theta = theta - MAX_TRIG;
157 return SinCosTab[theta];
160 /****************************************************************************/
162 #endif