1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
$NetBSD: patch-aa,v 1.1.1.1 2005/07/27 17:06:53 drochner Exp $
--- dbl2mpq.c.orig 2004-04-16 21:29:16.000000000 +0200
+++ dbl2mpq.c 2004-04-16 21:52:52.000000000 +0200
@@ -5,7 +5,7 @@
#include <float.h>
#include <gmp.h>
-#include <ieee754.h>
+#include <machine/ieee.h>
#include <stdlib.h>
#include "zelibm.h"
@@ -14,50 +14,50 @@
void
extract_double (mpq_t r, double d)
{
- union ieee754_double u;
+ union ieee_double_u u;
unsigned int val;
/* Make the floating point value available in the broken down form. We
cannot use casting of pointers and other ugly ways to access the bits.
Using the union is the only half-way clean method. */
- u.d = d;
+ u.dblu_d = d;
mpq_init (r);
/* Set the high word and the denominator to 1. */
- val = u.ieee.mantissa0;
- if (u.ieee.exponent != 0)
+ val = u.dblu_dbl.dbl_frach;
+ if (u.dblu_dbl.dbl_exp != 0)
val |= 1 << (DBL_MANT_DIG - 32 - 1);
mpq_set_ui (r, val, 1);
/* Shift in the right position. */
mpz_mul_2exp (mpq_numref (r), mpq_numref (r), 32);
/* Add the lower word. */
- mpz_add_ui (mpq_numref (r), mpq_numref (r), u.ieee.mantissa1);
+ mpz_add_ui (mpq_numref (r), mpq_numref (r), u.dblu_dbl.dbl_fracl);
- if (u.ieee.exponent == 0)
+ if (u.dblu_dbl.dbl_exp == 0)
{
- if (u.ieee.mantissa0 != 0 && u.ieee.mantissa1 != 0)
+ if (u.dblu_dbl.dbl_frach != 0 && u.dblu_dbl.dbl_fracl != 0)
{
/* The number is a denormalized. */
mpz_mul_2exp (mpq_denref (r), mpq_denref (r),
-DBL_MIN_EXP + DBL_MANT_DIG + 1);
}
}
- else if (u.ieee.exponent >= IEEE754_DOUBLE_BIAS + DBL_MANT_DIG)
+ else if (u.dblu_dbl.dbl_exp >= DBL_EXP_BIAS + DBL_MANT_DIG)
{
/* We have to multiply the numerator with the exponent. */
mpz_mul_2exp (mpq_numref (r), mpq_numref (r),
- (u.ieee.exponent
- - (IEEE754_DOUBLE_BIAS + DBL_MANT_DIG - 1)));
+ (u.dblu_dbl.dbl_exp
+ - (DBL_EXP_BIAS + DBL_MANT_DIG - 1)));
}
else
{
/* Set denominator to the appropriate power of 2. */
mpz_mul_2exp (mpq_denref (r), mpq_denref (r),
- ((IEEE754_DOUBLE_BIAS + DBL_MANT_DIG - 1)
- - u.ieee.exponent));
+ ((DBL_EXP_BIAS + DBL_MANT_DIG - 1)
+ - u.dblu_dbl.dbl_exp));
}
- if (u.ieee.negative)
+ if (u.dblu_dbl.dbl_sign)
mpq_neg (r, r);
}
|