1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* $Id: float_emul.c,v 1.5 2005/11/23 22:03:28 debug Exp $ |
* $Id: float_emul.c,v 1.9 2006/12/30 13:30:52 debug Exp $ |
28 |
* |
* |
29 |
* Floating point emulation routines. |
* Floating point emulation routines. |
30 |
*/ |
*/ |
142 |
fvp->f = fraction; |
fvp->f = fraction; |
143 |
|
|
144 |
#ifdef IEEE_DEBUG |
#ifdef IEEE_DEBUG |
145 |
fatal("{ ieee: x=%016llx sign=%i exponent=%i frac=%f ", |
fatal("{ ieee: x=%016"PRIx64" sign=%i exponent=%i frac=%f ", |
146 |
(long long)x, sign, exponent, fraction); |
(uint64_t) x, sign, exponent, fraction); |
147 |
#endif |
#endif |
148 |
|
|
149 |
/* TODO: this is awful for exponents of large magnitude. */ |
/* TODO: this is awful for exponents of large magnitude. */ |
232 |
|
|
233 |
/* |
/* |
234 |
* How to convert back from double to exponent + fraction: |
* How to convert back from double to exponent + fraction: |
235 |
* We want fraction to be 1.xxx, that is |
* The fraction should be 1.xxx, that is |
236 |
* 1.0 <= fraction < 2.0 |
* 1.0 <= fraction < 2.0 |
237 |
* |
* |
238 |
* This method is very slow but should work: |
* This method is very slow but should work: |
239 |
|
* (TODO: Fix the performance problem!) |
240 |
*/ |
*/ |
241 |
exponent = 0; |
exponent = 0; |
242 |
while (nf < 1.0 && exponent > -1023) { |
while (nf < 1.0 && exponent > -1023) { |
275 |
r = 0; |
r = 0; |
276 |
|
|
277 |
#ifdef IEEE_DEBUG |
#ifdef IEEE_DEBUG |
278 |
fatal(" exp=%i, r = %016llx }\n", exponent, (long long)r); |
fatal(" exp=%i, r = %016"PRIx64" }\n", exponent, (uint64_t) r); |
279 |
#endif |
#endif |
280 |
break; |
break; |
281 |
default:/* TODO */ |
default:/* TODO */ |