]> git.bts.cx Git - sun.git/blob - runtime/src/sun/vm/fixed.c
do not evaluate variables until they are used
[sun.git] / runtime / src / sun / vm / fixed.c
1 #include "fixed.h"
2
3 #include <math.h>
4
5 Fixed fixedSqrt(Fixed value) {
6 float f = FIXED_TO_FLOAT(value);
7 float f2 = sqrtf(f);
8 return FIXED_FROM_FLOAT(f2);
9
10
11 #if 0
12 Fixed root;
13
14 register unsigned long remHi, remLo, testDiv, count;
15
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 */
20
21 do {
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 */
26
27 if (remHi >= testDiv) {
28 remHi -= testDiv;
29 root.raw++;
30 }
31 } while (count-- != 0);
32
33 return(root);
34 #endif
35 }
36
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);
41 }
42
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);
47 }
48
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);
55 }
56
57 Fixed fixedAbs(Fixed value) {
58 float f = FIXED_TO_FLOAT(value);
59 float f2 = fabsf(f);
60 return FIXED_FROM_FLOAT(f2);
61 }
62
63 Fixed fixedCeil(Fixed value) {
64 float f = FIXED_TO_FLOAT(value);
65 float f2 = ceilf(f);
66 return FIXED_FROM_FLOAT(f2);
67 }
68
69 Fixed fixedFloor(Fixed value) {
70 float f = FIXED_TO_FLOAT(value);
71 float f2 = floorf(f);
72 return FIXED_FROM_FLOAT(f2);
73 }