summaryrefslogtreecommitdiffstats
path: root/lib/libI77/wref.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libI77/wref.c')
-rw-r--r--lib/libI77/wref.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/libI77/wref.c b/lib/libI77/wref.c
index 1ef2c47..eda9a8f 100644
--- a/lib/libI77/wref.c
+++ b/lib/libI77/wref.c
@@ -23,6 +23,9 @@ wrt_E(ufloat *p, int w, int d, int e, ftnlen len)
char buf[FMAX+EXPMAXDIGS+4], *s, *se;
int d1, delta, e1, i, sign, signspace;
double dd;
+#ifdef WANT_LEAD_0
+ int insert0 = 0;
+#endif
#ifndef VAX
int e0 = e;
#endif
@@ -53,6 +56,13 @@ wrt_E(ufloat *p, int w, int d, int e, ftnlen len)
}
delta = w - (2 /* for the . and the d adjustment above */
+ 2 /* for the E+ */ + signspace + d + e);
+#ifdef WANT_LEAD_0
+ if (f__scale <= 0 && delta > 0) {
+ delta--;
+ insert0 = 1;
+ }
+ else
+#endif
if (delta < 0) {
nogood:
while(--w >= 0)
@@ -91,8 +101,13 @@ nogood:
se = buf + d + 3;
#ifdef GOOD_SPRINTF_EXPONENT /* When possible, exponent has 2 digits. */
if (f__scale != 1 && dd)
-#endif
sprintf(se, "%+.2d", atoi(se) + 1 - f__scale);
+#else
+ if (dd)
+ sprintf(se, "%+.2d", atoi(se) + 1 - f__scale);
+ else
+ strcpy(se, "+00");
+#endif
s = ++se;
if (e < 2) {
if (*s != '0')
@@ -139,6 +154,10 @@ nogood:
s = buf;
i = f__scale;
if (f__scale <= 0) {
+#ifdef WANT_LEAD_0
+ if (insert0)
+ PUT('0');
+#endif
PUT('.');
for(; i < 0; ++i)
PUT('0');
@@ -211,8 +230,10 @@ wrt_F(ufloat *p, int w, int d, ftnlen len)
n = sprintf(b = buf, "%#.*f", d, x) + d1;
#endif
+#ifndef WANT_LEAD_0
if (buf[0] == '0' && d)
{ ++b; --n; }
+#endif
if (sign) {
/* check for all zeros */
for(s = b;;) {
@@ -229,9 +250,16 @@ wrt_F(ufloat *p, int w, int d, ftnlen len)
if (sign || f__cplus)
++n;
if (n > w) {
- while(--w >= 0)
- PUT('*');
- return 0;
+#ifdef WANT_LEAD_0
+ if (buf[0] == '0' && --n == w)
+ ++b;
+ else
+#endif
+ {
+ while(--w >= 0)
+ PUT('*');
+ return 0;
+ }
}
for(w -= n; --w >= 0; )
PUT(' ');
OpenPOWER on IntegriCloud