How many digits does octave use?!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How many digits does octave use?!

Francesco Potorti`-8
   octave:48> a=rand(1,1)/200;
   octave:49> sprintf("%.100g\n",a)
   ans = 0.0004910822212696075612925472597680709441192448139190673828125

   Thats 64 DIGITS! Where are they coming from?

That's even nicer (using the precompiled alpha binaries):

octave:1> sprintf("%.100g\n",1/3)
ans = 0.333333333333333314829616256247390992939472198486328125
--
Francesco Potorti`                  Voice:    +39-50-593203
CNUCE - Istituto del CNR            Operator: +39-50-593111
Via Santa Maria 36                  Fax:      +39-50-904052
56126 Pisa - Italy                  Email:    [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How many digits does octave use?!

Ted.Harding
>    octave:48> a=rand(1,1)/200;
>    octave:49> sprintf("%.100g\n",a)
>    ans = 0.0004910822212696075612925472597680709441192448139190673828125
>
>    Thats 64 DIGITS! Where are they coming from?
>
> That's even nicer (using the precompiled alpha binaries):
>
> octave:1> sprintf("%.100g\n",1/3)
> ans = 0.333333333333333314829616256247390992939472198486328125
> --
> Francesco Potorti`                  Voice:    +39-50-593203

Well, looking into this I typed the wrong thing, and ...

octave:28> sprintf("%.300g\n",1000000000/(8*8*8*8*8*8*8*8*8*8*8**88))
ans =
3.1418198177905449939812940511912164115041379279996477216713914349997473630218981481344626457838924494573974858016844022484274679106718200977968094874297366094419874972543116342649227590300142765045166015625e-80


I think I hold the record, so far.

Ted.                                    ([hidden email])

Reply | Threaded
Open this post in threaded view
|

Re: How many digits does octave use?!

John W. Eaton-6
Ted Harding <[hidden email]> wrote:

: Well, looking into this I typed the wrong thing, and ...
:
: octave:28> sprintf("%.300g\n",1000000000/(8*8*8*8*8*8*8*8*8*8*8**88))
: ans = 3.1418198177905449939812940511912164115041379279996477216713...

If anything, this is a bug in the iostream library distributed with
libg++.  Octave uses the following method of printing numbers (except
that the format string is determined at run-time):

  #include <math.h>
  #include <iostream.h>
  int
  main (void)
  {
    cout.form ("%.70g\n", M_PI);
    return 0;
  }

When compiled with g++ and linked with libg++, this program prints

  3.141592653589793115997963468544185161590576171875

on my DEC Alpha.

I don't think it's worth working around this problem in Octave.  It
should be fixed in libg++ instead.

jwe