Gerhard Niklasch on Wed, 4 Mar 1998 04:58:09 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: dependence of format and realprecision

I take the liberty of quoting this piece of personal mail back to the
list instead of paraphrasing it for context...

> Message-Id: <>
> Date: 	Wed, 4 Mar 1998 03:46:13 +0100
> To: (Gerhard Niklasch)
> From: Jack Fearnley <>
> When I do 
> default(format,"g0.7")
> I discover that
> default(realprecision)
> gives 7 as a response.

I missed this at first.

> I agree that your \x display seems to show that 100 digits is preserved
> internally, but why is this not reflected in the value of
> default(realprecision)?

Because setdrealprecision() would print out the current _format_'s
precision, in a misguided (IMHO) attempt not to surprise the user
(leading to a much greater surprise later as you discovered!),
instead of recomputing the actual precision-in-terms-of-decimal-digits
from the internal precision-in-terms-of-words (gp's global variable prec).

This may actually have been intentional, but now that I've tried out
the patch below, I find that I prefer the behavior it will give:  now
if you ask, on a 32-bit machine, for 9 digits, you get 9 (and it says
so in its immediate acknowledgement);  if you ask for 10, you get 19
(and it says so!), which is the next larger possibility;  if you ask
for 28, you get 28, ask for 29, and get 38...  (you have to go out to
several million digits before you begin to notice that the conversion
factors themselves, pariK and pariK1 in src/headers/paricom.h, are only
available with finite precision!).

The new version still resets the format when the precision is changed.
I think this is as it should be.  It would be trivial to disable it;
see the comment in the patch.

Enjoy, Gerhard

diff -u src/gp/gp.c.orig src/gp/gp.c
--- src/gp/gp.c.orig    Wed Mar  4 04:04:53 1998
+++ src/gp/gp.c Wed Mar  4 04:49:27 1998
@@ -876,19 +876,21 @@
 static GEN
 setdrealprecision(char *v, int status)
   if (*v)
-    long newnb = get_int(v, fmt.nb);
+    long oldnb = (long)((prec-2.)*pariK);
+    long newnb = get_int(v, oldnb);
-    if (fmt.nb==newnb) return gnil;
+    if (oldnb==newnb) return gnil;
     if (newnb < 0) err(talker,"default: negative real precision");
-    fmt.nb=newnb;
+    fmt.nb=newnb; /* should this be removed? -- GN1998Mar04 */
-    prec = (long) (fmt.nb*pariK1 + 3);
+    prec = (long) (newnb*pariK1 + 3);
   if (status == d_RETURN) return stoi(prec);
   if (status == d_ACKNOWLEDGE)
-    pariputsf("   realprecision = %ld significant digits\n",fmt.nb);
+    pariputsf("   realprecision = %ld significant digits\n",
+             (long)((prec-2.)*pariK));
   return gnil;