2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 #define NO_FIX_INLINE 1
23 //=============================== FIXED POINT ===============================
25 typedef int32_t fix; //16 bits int, 16 bits frac
26 typedef int16_t fixang; //angles
28 typedef struct quadint // integer 64 bit, previously called "quad"
36 //Convert an int to a fix
37 #define i2f(i) ((fix)((i)<<16))
39 //Get the int part of a fix
40 #define f2i(f) ((f)>>16)
42 //Get the int part of a fix, with rounding
43 #define f2ir(f) (((f)+f0_5)>>16)
45 //Convert fix to float and float to fix
46 #define f2fl(f) (((float) (f)) / 65536.0)
47 #define f2db(f) (((double) (f)) / 65536.0)
48 #define fl2f(f) ((fix) ((f) * 65536))
50 //Some handy constants
69 //#if defined(NO_FIX_INLINE) || (!defined(__GNUC__) && !defined(__WATCOMC__))
70 //multiply two fixes, return a fix
71 fix fixmul (fix a, fix b);
73 //divide two fixes, return a fix
74 fix fixdiv (fix a, fix b);
76 //multiply two fixes, then divide by a third, return a fix
77 fix fixmuldiv (fix a, fix b, fix c);
83 fix fixmul (fix a, fix b);
85 #pragma aux fixmul parm [eax] [edx] = \
91 fix fixdiv (fix a, fix b);
93 #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
100 fix fixmuldiv (fix a, fix b, fix c);
102 #pragma aux fixmuldiv parm [eax] [edx] [ebx] modify exact [eax edx] = \
106 //#elif defined (__GNUC__)
109 fixmul (fix a, fix b)
115 " shrd $16,%%edx,%%eax"
116 : "=a" (__retval): "a" (a), "d" (b):"%edx");
122 //multiply two fixes, return a fix
123 fix fixmul (fix a, fix b);
126 //divide two fixes, return a fix
127 fix fixdiv (fix a, fix b);
129 //multiply two fixes, then divide by a third, return a fix
130 fix fixmuldiv (fix a, fix b, fix c);
134 fixdiv (fix a, fix b)
137 register fix __retval;
139 asm (" mov %%eax,%%edx;"
142 " idiv %%ecx" /* adb: how to make this %0 w/o chance of edx? */
143 : "=a" (__retval): "a" (a), "c" (b):"%edx");
150 fixmuldiv (fix a, fix b, fix c)
153 register fix __retval;
156 " idiv %%ecx" /* adb: how to make this %0 w/o chance of edx? */
157 : "=a" (__retval): "a" (a), "r" (b), "c" (c):"%edx");
164 //#endif // __GNUC__ / __WATCOMC__
165 //#endif /* defined NO_FIX_INLINE || (!defined __GNUC__ && !defined __WATCOMC__) */
169 //multiply two fixes, and add 64-bit product to a quadint
170 void fixmulaccum (quadint * q, fix a, fix b);
172 //extract a fix from a quadint product
173 fix fixquadadjust (quadint * q);
175 //divide a quadint by a long
176 int32_t fixdivquadlong(uint32_t qlow, uint32_t qhigh, uint32_t d);
179 void fixquadnegate (quadint * q);
181 //computes the square root of a long, returning a short
182 ushort long_sqrt (int32_t a);
184 //computes the square root of a quadint, returning a long
185 uint32_t quad_sqrt(uint32_t low, int32_t high);
186 //unsigned long quad_sqrt (long low, long high);
188 //computes the square root of a fix, returning a fix
189 fix fix_sqrt (fix a);
191 //compute sine and cosine of an angle, filling in the variables
192 //either of the pointers can be NULL
193 void fix_sincos (fix a, fix * s, fix * c); //with interpolation
195 void fix_fastsincos (fix a, fix * s, fix * c); //no interpolation
197 //compute inverse sine & cosine
198 fixang fix_asin (fix v);
200 fixang fix_acos (fix v);
202 //given cos & sin of an angle, return that angle.
203 //parms need not be normalized, that is, the ratio of the parms cos/sin must
204 //equal the ratio of the actual cos & sin for the result angle, but the parms
205 //need not be the actual cos & sin.
206 //NOTE: this is different from the standard C atan2, since it is left-handed.
207 fixang fix_atan2 (fix cos, fix sin);
209 //for passed value a, returns 1/sqrt(a)
210 fix fix_isqrt (fix a);