1998-02-01 02:37:08 +01:00
|
|
|
#include "f2c.h"
|
|
|
|
#include "fio.h"
|
|
|
|
#ifndef VAX
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef abs
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "fmt.h"
|
|
|
|
#include "fp.h"
|
|
|
|
|
main.c (main): Avoid implicit int.
* libF77/main.c (main): Avoid implicit int.
* libI77/dfe.c (y_rsk, y_getc, c_dfe): Likewise.
* libI77/due.c (c_due): Likewise.
* libI77/err.c (f__canseek, f__nowreading, f__nowwriting):
Likewise.
* libI77/fmt.c (op_gen, ne_d, e_d, pars_f, type_f, en_fio):
Likewise.
* libI77/iio.c (z_getc, z_rnew, c_si, z_wnew): Likewise.
* libI77/lread.c (t_getc, c_le, l_read): Likewise.
* libI77/lwrite.c (l_write): Likewise.
* libI77/open.c (fk_open): Likewise.
* libI77/rdfmt.c (rd_ed, rd_ned): Likewise.
* libI77/rsfe.c (xrd_SL, x_getc, x_endp, x_rev): Likewise.
* libI77/rsne.c (t_getc, x_rsne): Likewise.
* libI77/sfe.c (c_sfe): Likewise.
* libI77/sue.c (c_sue): Likewise.
* libI77/uio.c (do_us): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wrtfmt.c (wrt_L, w_ed, w_ned): Likewise.
From-SVN: r54169
2002-06-02 15:01:12 +02:00
|
|
|
int
|
2002-06-01 14:38:32 +02:00
|
|
|
wrt_E (ufloat * p, int w, int d, int e, ftnlen len)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
char buf[FMAX + EXPMAXDIGS + 4], *s, *se;
|
|
|
|
int d1, delta, e1, i, sign, signspace;
|
|
|
|
double dd;
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef WANT_LEAD_0
|
2002-06-01 14:38:32 +02:00
|
|
|
int insert0 = 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
|
|
|
#ifndef VAX
|
2002-06-01 14:38:32 +02:00
|
|
|
int e0 = e;
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
if (e <= 0)
|
|
|
|
e = 2;
|
|
|
|
if (f__scale)
|
|
|
|
{
|
|
|
|
if (f__scale >= d + 2 || f__scale <= -d)
|
|
|
|
goto nogood;
|
|
|
|
}
|
|
|
|
if (f__scale <= 0)
|
|
|
|
--d;
|
|
|
|
if (len == sizeof (real))
|
|
|
|
dd = p->pf;
|
|
|
|
else
|
|
|
|
dd = p->pd;
|
|
|
|
if (dd < 0.)
|
|
|
|
{
|
|
|
|
signspace = sign = 1;
|
|
|
|
dd = -dd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sign = 0;
|
|
|
|
signspace = (int) f__cplus;
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifndef VAX
|
2002-06-01 14:38:32 +02:00
|
|
|
if (!dd)
|
|
|
|
dd = 0.; /* avoid -0 */
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
}
|
|
|
|
delta = w - (2 /* for the . and the d adjustment above */
|
|
|
|
+ 2 /* for the E+ */ + signspace + d + e);
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef WANT_LEAD_0
|
2002-06-01 14:38:32 +02:00
|
|
|
if (f__scale <= 0 && delta > 0)
|
|
|
|
{
|
|
|
|
delta--;
|
|
|
|
insert0 = 1;
|
|
|
|
}
|
|
|
|
else
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
if (delta < 0)
|
|
|
|
{
|
|
|
|
nogood:
|
|
|
|
while (--w >= 0)
|
|
|
|
PUT ('*');
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (f__scale < 0)
|
|
|
|
d += f__scale;
|
|
|
|
if (d > FMAX)
|
|
|
|
{
|
|
|
|
d1 = d - FMAX;
|
|
|
|
d = FMAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
d1 = 0;
|
|
|
|
sprintf (buf, "%#.*E", d, dd);
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifndef VAX
|
2002-06-01 14:38:32 +02:00
|
|
|
/* check for NaN, Infinity */
|
2002-06-04 04:25:48 +02:00
|
|
|
if (!isdigit ((unsigned char) buf[0]))
|
2002-06-01 14:38:32 +02:00
|
|
|
{
|
|
|
|
switch (buf[0])
|
|
|
|
{
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
signspace = 0; /* no sign for NaNs */
|
|
|
|
}
|
|
|
|
delta = w - strlen (buf) - signspace;
|
|
|
|
if (delta < 0)
|
|
|
|
goto nogood;
|
|
|
|
while (--delta >= 0)
|
|
|
|
PUT (' ');
|
|
|
|
if (signspace)
|
|
|
|
PUT (sign ? '-' : '+');
|
|
|
|
for (s = buf; *s; s++)
|
|
|
|
PUT (*s);
|
|
|
|
return 0;
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
se = buf + d + 3;
|
|
|
|
#ifdef GOOD_SPRINTF_EXPONENT /* When possible, exponent has 2 digits. */
|
|
|
|
if (f__scale != 1 && dd)
|
|
|
|
sprintf (se, "%+.2d", atoi (se) + 1 - f__scale);
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
2002-06-01 14:38:32 +02:00
|
|
|
if (dd)
|
|
|
|
sprintf (se, "%+.2d", atoi (se) + 1 - f__scale);
|
|
|
|
else
|
|
|
|
strcpy (se, "+00");
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
s = ++se;
|
|
|
|
if (e < 2)
|
|
|
|
{
|
|
|
|
if (*s != '0')
|
|
|
|
goto nogood;
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifndef VAX
|
2002-06-01 14:38:32 +02:00
|
|
|
/* accommodate 3 significant digits in exponent */
|
|
|
|
if (s[2])
|
|
|
|
{
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef Pedantic
|
2002-06-01 14:38:32 +02:00
|
|
|
if (!e0 && !s[3])
|
|
|
|
for (s -= 2, e1 = 2; s[0] = s[1]; s++);
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
/* Pedantic gives the behavior that Fortran 77 specifies, */
|
|
|
|
/* i.e., requires that E be specified for exponent fields */
|
|
|
|
/* of more than 3 digits. With Pedantic undefined, we get */
|
|
|
|
/* the behavior that Cray displays -- you get a bigger */
|
|
|
|
/* exponent field if it fits. */
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
2002-06-01 14:38:32 +02:00
|
|
|
if (!e0)
|
|
|
|
{
|
dfe.c (s_rdfe, s_wdfe): Wrap parentheses around assignment used as truth value.
* libI77/dfe.c (s_rdfe, s_wdfe): Wrap parentheses around
assignment used as truth value.
* libI77/due.c (s_rdue, s_wdue): Likewise.
* libI77/endfile.c (f_end): Likewise.
* libI77/iio.c (s_rsfi, s_wsfi): Likewise.
* libI77/lread.c (ERR, l_C, nmL_getc, s_rsle): Likewise.
* libI77/lwrite.c (l_g, l_put): Likewise.
* libI77/open.c (f_open): Likewise.
* libI77/rdfmt.c (rd_Z): Likewise.
* libI77/rsfe.c (s_rsfe): Likewise.
* libI77/rsne.c (hash, mk_hashtab, nl_init, getname, getdimen,
x_rsne, s_rsne): Likewise.
* libI77/sue.c (s_rsue, s_wsue): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wsfe.c (s_wsfe): Likewise.
* libI77/wsle.c (s_wsle): Likewise.
* libI77/wsne.c (s_wsne): Likewise.
From-SVN: r54172
2002-06-02 16:34:31 +02:00
|
|
|
for (s -= 2, e1 = 2; (s[0] = s[1]); s++)
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef CRAY
|
2002-06-01 14:38:32 +02:00
|
|
|
delta--;
|
|
|
|
if ((delta += 4) < 0)
|
|
|
|
goto nogood
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
;
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
else if (e0 >= 0)
|
|
|
|
goto shift;
|
|
|
|
else
|
|
|
|
e1 = e;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shift:
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
for (s += 2, e1 = 2; *s; ++e1, ++s)
|
|
|
|
if (e1 >= e)
|
|
|
|
goto nogood;
|
|
|
|
while (--delta >= 0)
|
|
|
|
PUT (' ');
|
|
|
|
if (signspace)
|
|
|
|
PUT (sign ? '-' : '+');
|
|
|
|
s = buf;
|
|
|
|
i = f__scale;
|
|
|
|
if (f__scale <= 0)
|
|
|
|
{
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef WANT_LEAD_0
|
2002-06-01 14:38:32 +02:00
|
|
|
if (insert0)
|
|
|
|
PUT ('0');
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
PUT ('.');
|
|
|
|
for (; i < 0; ++i)
|
|
|
|
PUT ('0');
|
|
|
|
PUT (*s);
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
else if (f__scale > 1)
|
|
|
|
{
|
|
|
|
PUT (*s);
|
|
|
|
s += 2;
|
|
|
|
while (--i > 0)
|
|
|
|
PUT (*s++);
|
|
|
|
PUT ('.');
|
|
|
|
}
|
|
|
|
if (d1)
|
|
|
|
{
|
|
|
|
se -= 2;
|
|
|
|
while (s < se)
|
|
|
|
PUT (*s++);
|
|
|
|
se += 2;
|
|
|
|
do
|
|
|
|
PUT ('0');
|
|
|
|
while (--d1 > 0);
|
|
|
|
}
|
|
|
|
while (s < se)
|
|
|
|
PUT (*s++);
|
|
|
|
if (e < 2)
|
|
|
|
PUT (s[1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (++e1 <= e)
|
|
|
|
PUT ('0');
|
|
|
|
while (*s)
|
|
|
|
PUT (*s++);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
|
main.c (main): Avoid implicit int.
* libF77/main.c (main): Avoid implicit int.
* libI77/dfe.c (y_rsk, y_getc, c_dfe): Likewise.
* libI77/due.c (c_due): Likewise.
* libI77/err.c (f__canseek, f__nowreading, f__nowwriting):
Likewise.
* libI77/fmt.c (op_gen, ne_d, e_d, pars_f, type_f, en_fio):
Likewise.
* libI77/iio.c (z_getc, z_rnew, c_si, z_wnew): Likewise.
* libI77/lread.c (t_getc, c_le, l_read): Likewise.
* libI77/lwrite.c (l_write): Likewise.
* libI77/open.c (fk_open): Likewise.
* libI77/rdfmt.c (rd_ed, rd_ned): Likewise.
* libI77/rsfe.c (xrd_SL, x_getc, x_endp, x_rev): Likewise.
* libI77/rsne.c (t_getc, x_rsne): Likewise.
* libI77/sfe.c (c_sfe): Likewise.
* libI77/sue.c (c_sue): Likewise.
* libI77/uio.c (do_us): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wrtfmt.c (wrt_L, w_ed, w_ned): Likewise.
From-SVN: r54169
2002-06-02 15:01:12 +02:00
|
|
|
int
|
2002-06-01 14:38:32 +02:00
|
|
|
wrt_F (ufloat * p, int w, int d, ftnlen len)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
int d1, sign, n;
|
|
|
|
double x;
|
|
|
|
char *b, buf[MAXINTDIGS + MAXFRACDIGS + 4], *s;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
x = (len == sizeof (real) ? p->pf : p->pd);
|
|
|
|
if (d < MAXFRACDIGS)
|
|
|
|
d1 = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d1 = d - MAXFRACDIGS;
|
|
|
|
d = MAXFRACDIGS;
|
|
|
|
}
|
|
|
|
if (x < 0.)
|
|
|
|
{
|
|
|
|
x = -x;
|
|
|
|
sign = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sign = 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifndef VAX
|
2002-06-01 14:38:32 +02:00
|
|
|
if (!x)
|
|
|
|
x = 0.;
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
|
dfe.c (s_rdfe, s_wdfe): Wrap parentheses around assignment used as truth value.
* libI77/dfe.c (s_rdfe, s_wdfe): Wrap parentheses around
assignment used as truth value.
* libI77/due.c (s_rdue, s_wdue): Likewise.
* libI77/endfile.c (f_end): Likewise.
* libI77/iio.c (s_rsfi, s_wsfi): Likewise.
* libI77/lread.c (ERR, l_C, nmL_getc, s_rsle): Likewise.
* libI77/lwrite.c (l_g, l_put): Likewise.
* libI77/open.c (f_open): Likewise.
* libI77/rdfmt.c (rd_Z): Likewise.
* libI77/rsfe.c (s_rsfe): Likewise.
* libI77/rsne.c (hash, mk_hashtab, nl_init, getname, getdimen,
x_rsne, s_rsne): Likewise.
* libI77/sue.c (s_rsue, s_wsue): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wsfe.c (s_wsfe): Likewise.
* libI77/wsle.c (s_wsle): Likewise.
* libI77/wsne.c (s_wsne): Likewise.
From-SVN: r54172
2002-06-02 16:34:31 +02:00
|
|
|
if ((n = f__scale))
|
2002-06-02 14:57:28 +02:00
|
|
|
{
|
|
|
|
if (n > 0)
|
|
|
|
do
|
|
|
|
x *= 10.;
|
|
|
|
while (--n > 0);
|
|
|
|
else
|
|
|
|
do
|
|
|
|
x *= 0.1;
|
|
|
|
while (++n < 0);
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
|
|
|
|
#ifdef USE_STRLEN
|
2002-06-01 14:38:32 +02:00
|
|
|
sprintf (b = buf, "%#.*f", d, x);
|
|
|
|
n = strlen (b) + d1;
|
1998-02-01 02:37:08 +01:00
|
|
|
#else
|
2002-06-01 14:38:32 +02:00
|
|
|
n = sprintf (b = buf, "%#.*f", d, x) + d1;
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WANT_LEAD_0
|
2002-06-01 14:38:32 +02:00
|
|
|
if (buf[0] == '0' && d)
|
|
|
|
{
|
|
|
|
++b;
|
|
|
|
--n;
|
|
|
|
}
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
if (sign)
|
|
|
|
{
|
|
|
|
/* check for all zeros */
|
|
|
|
for (s = b;;)
|
|
|
|
{
|
|
|
|
while (*s == '0')
|
|
|
|
s++;
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
case '.':
|
|
|
|
s++;
|
|
|
|
continue;
|
|
|
|
case 0:
|
|
|
|
sign = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sign || f__cplus)
|
|
|
|
++n;
|
|
|
|
if (n > w)
|
|
|
|
{
|
1998-02-01 02:37:08 +01:00
|
|
|
#ifdef WANT_LEAD_0
|
2002-06-01 14:38:32 +02:00
|
|
|
if (buf[0] == '0' && --n == w)
|
|
|
|
++b;
|
|
|
|
else
|
1998-02-01 02:37:08 +01:00
|
|
|
#endif
|
2002-06-01 14:38:32 +02:00
|
|
|
{
|
|
|
|
while (--w >= 0)
|
|
|
|
PUT ('*');
|
|
|
|
return 0;
|
1998-02-01 02:37:08 +01:00
|
|
|
}
|
2002-06-01 14:38:32 +02:00
|
|
|
}
|
|
|
|
for (w -= n; --w >= 0;)
|
|
|
|
PUT (' ');
|
|
|
|
if (sign)
|
|
|
|
PUT ('-');
|
|
|
|
else if (f__cplus)
|
|
|
|
PUT ('+');
|
dfe.c (s_rdfe, s_wdfe): Wrap parentheses around assignment used as truth value.
* libI77/dfe.c (s_rdfe, s_wdfe): Wrap parentheses around
assignment used as truth value.
* libI77/due.c (s_rdue, s_wdue): Likewise.
* libI77/endfile.c (f_end): Likewise.
* libI77/iio.c (s_rsfi, s_wsfi): Likewise.
* libI77/lread.c (ERR, l_C, nmL_getc, s_rsle): Likewise.
* libI77/lwrite.c (l_g, l_put): Likewise.
* libI77/open.c (f_open): Likewise.
* libI77/rdfmt.c (rd_Z): Likewise.
* libI77/rsfe.c (s_rsfe): Likewise.
* libI77/rsne.c (hash, mk_hashtab, nl_init, getname, getdimen,
x_rsne, s_rsne): Likewise.
* libI77/sue.c (s_rsue, s_wsue): Likewise.
* libI77/wref.c (wrt_E, wrt_F): Likewise.
* libI77/wsfe.c (s_wsfe): Likewise.
* libI77/wsle.c (s_wsle): Likewise.
* libI77/wsne.c (s_wsne): Likewise.
From-SVN: r54172
2002-06-02 16:34:31 +02:00
|
|
|
while ((n = *b++))
|
2002-06-01 14:38:32 +02:00
|
|
|
PUT (n);
|
|
|
|
while (--d1 >= 0)
|
|
|
|
PUT ('0');
|
|
|
|
return 0;
|
|
|
|
}
|