~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to debian/patches/trim-excess-digits-from-printed-floats

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2013-01-15 20:46:25 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130115204625-3yvslgr556rfb8yi
Tags: 2.6.7+dfsga-1
* Acknowledge Non-maintainer upload. 
(thanks David Prévot <taffit@debian.org>) 
* Remove unused and non DFSG-compliant gmp3/gmp.* from source. 
(Closes: #695721)
* Show translated debconf templates, thanks to Denis Barbier for the
  analysis and the proposed fixes. (Closes: #691946)
* trim excess digits from printed floats

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: <short summary of the patch>
 
2
 TODO: Put a short summary on the line above and replace this paragraph
 
3
 with a longer explanation of this change. Complete the meta-information
 
4
 with other relevant fields (see below for details). To make it easier, the
 
5
 information below has been extracted from the changelog. Adjust it or drop
 
6
 it.
 
7
 .
 
8
 gcl (2.6.7a-1) unstable; urgency=high
 
9
 .
 
10
   * Accept Non-maintainer upload. (thanks David Prévot <taffit@debian.org>)
 
11
   * Remove unused and non DFSG-compliant gmp3/gmp.* from source.   (Closes: #695721)
 
12
   * Show translated debconf templates, thanks to Denis Barbier for the
 
13
     analysis and the proposed fixes. (Closes: #691946)
 
14
   * trim excess digits from printed floats
 
15
Author: Camm Maguire <camm@debian.org>
 
16
Bug-Debian: http://bugs.debian.org/691946
 
17
Bug-Debian: http://bugs.debian.org/695721
 
18
 
 
19
---
 
20
The information above should follow the Patch Tagging Guidelines, please
 
21
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
 
22
are templates for supplementary fields that you might want to add:
 
23
 
 
24
Origin: <vendor|upstream|other>, <url of original patch>
 
25
Bug: <url in upstream bugtracker>
 
26
Bug-Debian: http://bugs.debian.org/<bugnumber>
 
27
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
 
28
Forwarded: <no|not-needed|url proving that it has been forwarded>
 
29
Reviewed-By: <name and email of someone who approved the patch>
 
30
Last-Update: <YYYY-MM-DD>
 
31
 
 
32
--- gcl-2.6.7a.orig/o/print.d
 
33
+++ gcl-2.6.7a/o/print.d
 
34
@@ -303,76 +303,99 @@ write_base(void)
 
35
 
 
36
 object sSAprint_nansA;
 
37
 
 
38
+#include <string.h>
 
39
+
 
40
+static int
 
41
+char_inc(char *b,char *p) {
 
42
+
 
43
+  if (b==p) {
 
44
+    if (*p=='-') {
 
45
+      p++;
 
46
+      memmove(p+1,p,strlen(p)+1);
 
47
+    }
 
48
+    *p='1';
 
49
+  } else if (*p=='9') {
 
50
+    *p='0';
 
51
+    char_inc(b,p-1);
 
52
+  } else if (*p=='.')
 
53
+    char_inc(b,p-1);
 
54
+  else (*p)++;
 
55
+
 
56
+  return 1;
 
57
+
 
58
+}
 
59
+
 
60
+#define COMP(a_,b_,c_,d_) ((d_) ? strtod((a_),(b_))==(c_) : strtof((a_),(b_))==(float)(c_))
 
61
+
 
62
+static int
 
63
+truncate_double(char *b,double d,int dp) {
 
64
+
 
65
+  char c[FPRC+9],c1[FPRC+9],*p,*pp,*n;
 
66
+  int j,k;
 
67
+
 
68
+  n=b;
 
69
+  k=strlen(n);
 
70
+
 
71
+  strcpy(c1,b);
 
72
+  for (p=c1;*p && *p!='e';p++);
 
73
+  pp=p>c1 && p[-1]!='.' ? p-1 : p;
 
74
+  for (;pp>c1 && pp[-1]=='0';pp--);
 
75
+  strcpy(pp,p);
 
76
+  if (pp!=p && COMP(c1,&pp,d,dp))
 
77
+    k=truncate_double(n=c1,d,dp);
 
78
+
 
79
+  strcpy(c,n);
 
80
+  for (p=c;*p && *p!='e';p++);
 
81
+  if (p[-1]!='.' && char_inc(c,p-1) && COMP(c,&pp,d,dp)) {
 
82
+    j=truncate_double(c,d,dp);
 
83
+    if (j<k) {
 
84
+      k=j;
 
85
+      n=c;
 
86
+    }
 
87
+  }
 
88
+
 
89
+  if (n!=b) strcpy(b,n);
 
90
+  return k;
 
91
+
 
92
+}
 
93
+
 
94
 void
 
95
-edit_double(n, d, sp, s, ep)
 
96
-int n;
 
97
-double d;
 
98
-char *s;
 
99
-int *sp;
 
100
-int *ep;
 
101
-{
 
102
-       char *p, buff[FPRC + 9];
 
103
-       int i;
 
104
+edit_double(int n, double d, int *sp, char *s, int *ep) {
 
105
 
 
106
-#ifdef IEEEFLOAT
 
107
-/*     if ((*((int *)&d +HIND) & 0x7ff00000) == 0x7ff00000)*/
 
108
-       if (!ISFINITE(d))
 
109
-           {if (sSAprint_nansA->s.s_dbind !=Cnil)
 
110
-             {sprintf(s, "%e",d);
 
111
-              *sp = 2;
 
112
-              return;
 
113
-            }
 
114
-          else
 
115
-               FEerror("Can't print a non-number.",
 
116
-                       0);}
 
117
-       else
 
118
-               sprintf(buff, "%*.*e",FPRC+8,FPRC, d);
 
119
-       if (buff[FPRC+3] != 'e') {
 
120
-               sprintf(buff, "%*.*e",FPRC+7,FPRC,d);
 
121
-               *ep = (buff[FPRC+5]-'0')*10 + (buff[FPRC+6]-'0');
 
122
-       } else
 
123
-               *ep = (buff[FPRC+5]-'0')*100 +
 
124
-                 (buff[FPRC+6]-'0')*10 + (buff[FPRC+7]-'0');
 
125
-       *sp = 1;
 
126
-       if (buff[0] == '-')
 
127
-               *sp *= -1;
 
128
-#else
 
129
-       sprintf(buff, "%*.*e",FPRC+7,FPRC, d);
 
130
-       /*  "-D.MMMMMMMMMMMMMMMe+EE"  */
 
131
-       /*   0123456789012345678901   */
 
132
-       *sp = 1;
 
133
-       if (buff[0] == '-')
 
134
-               *sp *= -1;
 
135
-       *ep = (buff[FPRC+5]-'0')*10 + (buff[FPRC+6]-'0');
 
136
-#endif
 
137
-
 
138
-       if (buff[FPRC+4] == '-')
 
139
-               *ep *= -1;
 
140
-       buff[2] = buff[1];
 
141
-       p = buff + 2;
 
142
-       if (n < FPRC+1) {
 
143
-               if (p[n] >= '5') {
 
144
-                       for (i = n - 1;  i >= 0;  --i)
 
145
-                               if (p[i] == '9')
 
146
-                                       p[i] = '0';
 
147
-                               else {
 
148
-                                       p[i]++;
 
149
-                                       break;
 
150
-                               }
 
151
-                       if (i < 0) {
 
152
-                               *--p = '1';
 
153
-                               (*ep)++;
 
154
-                       }
 
155
-               }
 
156
-               for (i = 0;  i < n;  i++)
 
157
-                       s[i] = p[i];
 
158
-       } else {
 
159
-               for (i = 0;  i < FPRC+1;  i++)
 
160
-                       s[i] = p[i];
 
161
-               for (;  i < n;  i++)
 
162
-                       s[i] = '0';
 
163
-       }
 
164
-       s[n] = '\0';
 
165
+  char *p, b[FPRC + 9];
 
166
+  int i;
 
167
+  
 
168
+  if (!ISFINITE(d)) {
 
169
+    if (sSAprint_nansA->s.s_dbind !=Cnil) {
 
170
+      sprintf(s, "%e",d);
 
171
+      *sp = 2;
 
172
+      return;
 
173
+    }
 
174
+    else
 
175
+      FEerror("Can't print a non-number.",0);}
 
176
+  else
 
177
+    sprintf(b, "%*.*e",FPRC+8,FPRC, d);
 
178
+  if (b[FPRC+3] != 'e') {
 
179
+    sprintf(b, "%*.*e",FPRC+7,FPRC,d);
 
180
+    *ep = (b[FPRC+5]-'0')*10 + (b[FPRC+6]-'0');
 
181
+  } else
 
182
+    *ep = (b[FPRC+5]-'0')*100 + (b[FPRC+6]-'0')*10 + (b[FPRC+7]-'0');
 
183
+  *sp = 1;
 
184
+  if (b[0] == '-')
 
185
+    *sp *= -1;
 
186
+  if (b[FPRC+4] == '-')
 
187
+    *ep *= -1;
 
188
+
 
189
+  truncate_double(b,d,n!=7);
 
190
+
 
191
+  if (b[2]=='0') (*ep)++;
 
192
+  b[2] = b[1];
 
193
+  p = b + 2;
 
194
+  for (i=0;i<n && i<FPRC+1 && isdigit(p[i]);i++)
 
195
+      s[i] = p[i];
 
196
+  for (;i<n;i++)
 
197
+    s[i] = '0';
 
198
+  s[n] = '\0';
 
199
 }
 
200
 
 
201
 static void
 
202
@@ -405,7 +428,7 @@ bool shortp;
 
203
                        for (i = 0;  i < exp;  i++)
 
204
                                write_ch('0');
 
205
                        for (;  n > 0;  --n)
 
206
-                               if (buff[n-1] != '0')
 
207
+                               if (buff[n-1] != '0' && buff[n-1])
 
208
                                        break;
 
209
                        if (exp == 0 && n == 0)
 
210
                                n = 1;
 
211
@@ -425,7 +448,7 @@ bool shortp;
 
212
                                write_ch('0');
 
213
                        i++;
 
214
                        for (;  n > i;  --n)
 
215
-                               if (buff[n-1] != '0')
 
216
+                               if (buff[n-1] != '0' && buff[n-1])
 
217
                                        break;
 
218
                        for (;  i < n;  i++)
 
219
                                write_ch(buff[i]);
 
220
@@ -436,7 +459,7 @@ bool shortp;
 
221
                write_ch('.');
 
222
                write_ch(buff[1]);
 
223
                for (;  n > 2;  --n)
 
224
-                       if (buff[n-1] != '0')
 
225
+                       if (buff[n-1] != '0' && buff[n-1])
 
226
                                break;
 
227
                for (i = 2;  i < n;  i++)
 
228
                        write_ch(buff[i]);