|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * MC68881 emulation
5: *
6: * Conversion routines for hosts with unknown floating point format.
7: *
8: * Copyright 1996 Herman ten Brugge
9: */
10:
1.1.1.2 ! root 11: #ifndef UAE_FPP_UNKNOWN_H
! 12: #define UAE_FPP_UNKNOWN_H
! 13:
! 14: #include "uae/types.h"
! 15:
1.1 root 16: #ifndef HAVE_to_single
17: STATIC_INLINE double to_single (uae_u32 value)
18: {
19: double frac;
20:
21: if ((value & 0x7fffffff) == 0)
22: return (0.0);
23: frac = (double) ((value & 0x7fffff) | 0x800000) / 8388608.0;
24: if (value & 0x80000000)
25: frac = -frac;
26: return (ldexp (frac, ((value >> 23) & 0xff) - 127));
27: }
28: #endif
29:
30: #ifndef HAVE_from_single
31: STATIC_INLINE uae_u32 from_single (double src)
32: {
33: int expon;
34: uae_u32 tmp;
35: double frac;
36:
37: if (src == 0.0)
38: return 0;
39: if (src < 0) {
40: tmp = 0x80000000;
41: src = -src;
42: } else {
43: tmp = 0;
44: }
45: frac = frexp (src, &expon);
46: frac += 0.5 / 16777216.0;
47: if (frac >= 1.0) {
48: frac /= 2.0;
49: expon++;
50: }
51: return (tmp | (((expon + 127 - 1) & 0xff) << 23) |
52: (((int) (frac * 16777216.0)) & 0x7fffff));
53: }
54: #endif
55:
56: #ifndef HAVE_to_exten
57: STATIC_INLINE double to_exten(uae_u32 wrd1, uae_u32 wrd2, uae_u32 wrd3)
58: {
59: double frac;
60:
61: if ((wrd1 & 0x7fff0000) == 0 && wrd2 == 0 && wrd3 == 0)
62: return 0.0;
63: frac = (double) wrd2 / 2147483648.0 +
64: (double) wrd3 / 9223372036854775808.0;
65: if (wrd1 & 0x80000000)
66: frac = -frac;
67: return ldexp (frac, ((wrd1 >> 16) & 0x7fff) - 16383);
68: }
69: #endif
70:
71: #ifndef HAVE_from_exten
72: STATIC_INLINE void from_exten(double src, uae_u32 * wrd1, uae_u32 * wrd2, uae_u32 * wrd3)
73: {
74: int expon;
75: double frac;
76:
77: if (src == 0.0) {
78: *wrd1 = 0;
79: *wrd2 = 0;
80: *wrd3 = 0;
81: return;
82: }
83: if (src < 0) {
84: *wrd1 = 0x80000000;
85: src = -src;
86: } else {
87: *wrd1 = 0;
88: }
89: frac = frexp (src, &expon);
90: frac += 0.5 / 18446744073709551616.0;
91: if (frac >= 1.0) {
92: frac /= 2.0;
93: expon++;
94: }
95: *wrd1 |= (((expon + 16383 - 1) & 0x7fff) << 16);
96: *wrd2 = (uae_u32) (frac * 4294967296.0);
97: *wrd3 = (uae_u32) (frac * 18446744073709551616.0 - *wrd2 * 4294967296.0);
98: }
99: #endif
100:
101: #ifndef HAVE_to_double
102: STATIC_INLINE double to_double(uae_u32 wrd1, uae_u32 wrd2)
103: {
104: double frac;
105:
106: if ((wrd1 & 0x7fffffff) == 0 && wrd2 == 0)
107: return 0.0;
108: frac = (double) ((wrd1 & 0xfffff) | 0x100000) / 1048576.0 +
109: (double) wrd2 / 4503599627370496.0;
110: if (wrd1 & 0x80000000)
111: frac = -frac;
112: return ldexp (frac, ((wrd1 >> 20) & 0x7ff) - 1023);
113: }
114: #endif
115:
116: #ifndef HAVE_from_double
117: STATIC_INLINE void from_double(double src, uae_u32 * wrd1, uae_u32 * wrd2)
118: {
119: int expon;
120: int tmp;
121: double frac;
122:
123: if (src == 0.0) {
124: *wrd1 = 0;
125: *wrd2 = 0;
126: return;
127: }
128: if (src < 0) {
129: *wrd1 = 0x80000000;
130: src = -src;
131: } else {
132: *wrd1 = 0;
133: }
134: frac = frexp (src, &expon);
135: frac += 0.5 / 9007199254740992.0;
136: if (frac >= 1.0) {
137: frac /= 2.0;
138: expon++;
139: }
140: tmp = (uae_u32) (frac * 2097152.0);
141: *wrd1 |= (((expon + 1023 - 1) & 0x7ff) << 20) | (tmp & 0xfffff);
142: *wrd2 = (uae_u32) (frac * 9007199254740992.0 - tmp * 4294967296.0);
143: }
144: #endif
1.1.1.2 ! root 145:
! 146: #endif /* UAE_FPP_UNKNOWN_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.