| Ilya Zakharevich on Fri, 9 Oct 1998 18:41:24 -0400 (EDT) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Improved variant of patch to plot() (fwd) |
ilya writes:
Here is the improved variant of the improved variant! (Sorry for a
duplicate mail I sent a couple of minutes ago).
With sin(x^3)/3^-300 you get
7.31e-144 |'_x'''''''''x'''''''x'''''''''''''''''"''''"''''''''_'''''''''|
| :: ": _: xx x : : : " |
|: : :: :: :: ": : : __ : : |
|: " : : : : :: :: : : :: :: : _ |
|x : : : : : :: :: : : :: :: :: :: :" |
|: : : " : : : : :: : : : : :: :: :: :: |
|: : " : : _ : : : : : : : : :: _: :: :: |
: : : : : : : : : : " x x : :: : : ": :: |
: x : : _ : : : : : : : : : :: : : :: :: |
x : : : : : _ _ : : : : : " : : : : : : :: |
| : : : : : : : : : : : : : : : : : : : :: |
``````:```:````:```:```:``:``:``:``"``:`:``:`:`:``:`:`:`:`::`:``
| : : : : : : : x : : : : : : : : : : :: :|
| : x " : : : : : : : :: : : :: : : :: :|
| _ : : : : : : : : : :: : : :: x: :: :"
| : : : : _ : : : : : :: :: :: :: :: ::
| : : : : : : : : :: :: :_ _: :: ": ::
| : : : " : : :: :: :: :: :: :: :: :|
| : : : : :: :: :_ :: :: : : : :|
| : x _: :" x: : x_ : : : _ :|
| " : : : _ : x : x|
-7.3e-144 |......._........_......x......".............."........".......|
2.333333 4.333333
(This - -7.3e-144 - is the worst significant-digits lossage I can
imagine for a 9-chars field).
Enjoy,
Ilya
--- pari-2.0.11.beta/src/graph/plotport.c~ Thu Oct 8 02:10:20 1998
+++ pari-2.0.11.beta/src/graph/plotport.c Fri Oct 9 18:37:25 1998
@@ -47,15 +47,29 @@ PARI_plot pari_plot, pari_psplot;
#define XX_LOWER '.'
#define FF1 '_'
#define FF2 'x'
-#define FF3 '*'
+#define FF3 '"'
#define PICT(j) ((j) % 3 ? ((j) % 3 == 2 ? FF3 : FF2) : FF1)
+static char *
+dsprintf9(double d, char *buf)
+{
+ int i = 10;
+
+ while (--i >= 0) {
+ sprintf(buf, "%9.*g", i, d);
+ if (strlen(buf) <= 9)
+ return buf;
+ }
+ return buf; /* Should not happen? */
+}
+
void
plot(entree *ep, GEN a, GEN b, char *ch)
{
long av = avma, av2,limite,jz,j,i,sig;
GEN p1,p2,ysml,ybig,x,diff,dyj,dx,y[ISCR+1];
- char scr[ISCR+1][JSCR+1], z;
+ char scr[ISCR+1][JSCR+1], z, jprev, jnew;
+ char buf[80];
sig=gcmp(b,a); if (!sig) return;
if (sig<0) { x=a; a=b; b=x; }
@@ -94,10 +108,39 @@ plot(entree *ep, GEN a, GEN b, char *ch)
for (i=1; i<=ISCR; i++)
{
scr[i][jz]=z; j=3+gtolong(gmul(gsub(y[i],ysml),dyj));
- scr[i][j/3] = PICT(j); avma=av2;
+ jnew = j/3;
+ if (i > 1) {
+ int i_up, i_down, mid = (jprev + jnew)/2, up, down;
+ int domid = 0, jmid;
+
+ /* If the gap is 1, leave it as it is. */
+ if (jprev < jnew - 2) {
+ i_up = i;
+ i_down = i - 1;
+ up = jnew - 1;
+ down = jprev + 1;
+ domid = 1;
+ } else if (jnew < jprev - 2) {
+ i_up = i - 1;
+ i_down = i;
+ down = jnew + 1;
+ up = jprev - 1;
+ domid = 1;
+ }
+ if (domid) {
+ while (down <= mid) {
+ scr[i_down][down++] = ':';
+ }
+ while (up > mid) {
+ scr[i_up][up--] = ':';
+ }
+ }
+ }
+ scr[i][jnew] = PICT(j); avma=av2;
+ jprev = jnew;
}
p1=cgetr(3); gaffect(ybig,p1); pariputc('\n');
- pariputsf(" %8.3e",rtodbl(p1));
+ pariputsf("%s ", dsprintf9(rtodbl(p1), buf));
for (i=1; i<=ISCR; i++) pariputc(scr[i][JSCR]);
pariputc('\n');
for (j=(JSCR-1); j>=2; j--)
@@ -107,12 +150,12 @@ plot(entree *ep, GEN a, GEN b, char *ch)
pariputc('\n');
}
p1=cgetr(3); gaffect(ysml,p1);
- pariputsf("%8.3e",rtodbl(p1));
+ pariputsf("%s ", dsprintf9(rtodbl(p1), buf));
for (i=1; i<=ISCR; i++) pariputc(scr[i][1]);
pariputc('\n');
p1=cgetr(3); gaffect(a,p1);
p2=cgetr(3); gaffect(b,p2);
- pariputsf("%8s %8.3e %44s %8.3e\n"," ",rtodbl(p1)," ",rtodbl(p2));
+ pariputsf("%10s%-9.7g%*.7g\n"," ",rtodbl(p1),ISCR-9,rtodbl(p2));
pop_val(ep); avma=av;
}