]>
git.bts.cx Git - sun.git/blob - runtime/src/sun/vm/fixed.c
5 Fixed
fixedSqrt(Fixed value
) {
6 float f
= FIXED_TO_FLOAT(value
);
8 return FIXED_FROM_FLOAT(f2
);
14 register unsigned long remHi
, remLo
, testDiv
, count
;
16 root
.raw
= 0;/* Clear root */
17 remHi
= 0;/* Clear high part of partial remainder */
18 remLo
= value
.raw
;/* Get argument into low part of partial remainder */
19 count
= FIXED_FRACTIONAL_BITS
;/* Load loop counter */
22 remHi
= (remHi
<< FIXED_INTEGRAL_BITS
) | (remLo
>> FIXED_FRACTIONAL_BITS
);
23 remLo
<<= 2; /* get 2 bits of arg */
24 root
.raw
<<= 1; /* Get ready for the next bit in the root */
25 testDiv
= (root
.raw
<< 1) + 1;/* Test radical */
27 if (remHi
>= testDiv
) {
31 } while (count
-- != 0);
37 Fixed
fixedSin(Fixed value
) {
38 float f
= FIXED_TO_FLOAT(value
);
39 float f2
= sinf(f
* M_PI
* 2.0f
);
40 return FIXED_FROM_FLOAT(f2
);
43 Fixed
fixedCos(Fixed value
) {
44 float f
= FIXED_TO_FLOAT(value
);
45 float f2
= cosf(f
* M_PI
* 2.0f
);
46 return FIXED_FROM_FLOAT(f2
);
49 Fixed
fixedAtan2(Fixed x
, Fixed y
) {
50 float f1
= FIXED_TO_FLOAT(y
); // Notice swap
51 float f2
= FIXED_TO_FLOAT(x
);
52 float f3
= atan2f(f1
, f2
);
53 float f4
= f3
/ (M_PI
* 2.0f
);
54 return FIXED_FROM_FLOAT(f4
);
57 Fixed
fixedAbs(Fixed value
) {
58 float f
= FIXED_TO_FLOAT(value
);
60 return FIXED_FROM_FLOAT(f2
);
63 Fixed
fixedCeil(Fixed value
) {
64 float f
= FIXED_TO_FLOAT(value
);
66 return FIXED_FROM_FLOAT(f2
);
69 Fixed
fixedFloor(Fixed value
) {
70 float f
= FIXED_TO_FLOAT(value
);
72 return FIXED_FROM_FLOAT(f2
);