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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
===================================================================
RCS file: RCS/printcmd.c,v
retrieving revision 1.1
diff -c3 -r1.1 printcmd.c
*** /tmp/,RCSt1011248 Tue Jan 12 14:06:06 1988
--- printcmd.c Mon Sep 21 21:33:39 1987
***************
*** 174,179
VALUE_TYPE (val) = builtin_type_float;
if (TYPE_LENGTH (VALUE_TYPE (val)) == sizeof (double))
VALUE_TYPE (val) = builtin_type_double;
printf ("%g", value_as_double (val));
break;
--- 174,185 -----
VALUE_TYPE (val) = builtin_type_float;
if (TYPE_LENGTH (VALUE_TYPE (val)) == sizeof (double))
VALUE_TYPE (val) = builtin_type_double;
+ #ifdef PRINTF_BUG
+ if (is_nan(value_as_double (val)))
+ printf ("Nan");
+ else
+ printf ("%g", value_as_double (val));
+ #else
printf ("%g", value_as_double (val));
#endif
break;
***************
*** 175,180
if (TYPE_LENGTH (VALUE_TYPE (val)) == sizeof (double))
VALUE_TYPE (val) = builtin_type_double;
printf ("%g", value_as_double (val));
break;
case 0:
--- 181,187 -----
printf ("%g", value_as_double (val));
#else
printf ("%g", value_as_double (val));
+ #endif
break;
case 0:
===================================================================
RCS file: RCS/valprint.c,v
retrieving revision 1.1
diff -c3 -r1.1 valprint.c
*** /tmp/,RCSt1011248 Tue Jan 12 14:06:09 1988
--- valprint.c Mon Sep 21 21:35:45 1987
***************
*** 21,26
#include <stdio.h>
#include "defs.h"
#include "initialize.h"
#include "symtab.h"
#include "value.h"
--- 21,27 -----
#include <stdio.h>
#include "defs.h"
#include "initialize.h"
+ #include "param.h"
#include "symtab.h"
#include "value.h"
***************
*** 249,255
break;
case TYPE_CODE_FLT:
! fprintf (stream, "%g", unpack_double (type, valaddr));
break;
case TYPE_CODE_VOID:
--- 250,265 -----
break;
case TYPE_CODE_FLT:
! { double d = unpack_double (type, valaddr);
! #ifdef PRINTF_BUG
! if (is_nan(d))
! fprintf (stream, "Nan");
! else
! fprintf (stream, "%g", d);
! #else
! fprintf (stream, "%g", d);
! #endif
! }
break;
case TYPE_CODE_VOID:
***************
*** 559,563
float_type_table[sizeof (float)] = "float";
float_type_table[sizeof (double)] = "double";
}
END_FILE
--- 569,599 -----
float_type_table[sizeof (float)] = "float";
float_type_table[sizeof (double)] = "double";
}
+
+
+ #ifdef PRINTF_BUG
+
+ struct ieee { /* IEEE floating format */
+ unsigned int s:1;
+ unsigned int e:11;
+ unsigned int f1:20;
+ unsigned int f2;
+ };
+
+ #define ZERO_F(x) ((x.f1 == 0) && (x.f2 == 0)) /* zero fraction ? */
+ #define ZERO_E(x) (x.e == 0) /* zero exponential ? */
+ #define MAX_E(x) (x.e == 0x7ff) /* max exponential ? */
+ #define MINUS_S(x) (x.s == 1) /* minus ? */
+
+ int
+ is_nan(arg) /* Not a Number ? */
+ struct ieee arg;
+ {
+ if (MAX_E(arg) && !ZERO_F(arg))
+ return (1);
+ else
+ return (0);
+ }
+ #endif
END_FILE
|