Post Reply 
(16C) e to 400 decimal places
02-12-2015, 06:53 PM
Post: #10
RE: (HP-16C) e to 400 decimal places
(02-11-2015 02:33 PM)Frido Bohn Wrote:  Wow! This is a very fine example how programs should be written.

Here's a very fine example how programs should not be written:
Code:
a[87700],b,c=87700,d,e=1e4,f=1e5,h;
main(){for(;b=c--,b>84700;h=printf("%05d",e+d/f),e=d%=f)
for(;--b;d+=f*(h?a[b]:e),a[b]=d%b,d/=b);}

It calculates e to 15000 places in ~ 4.7 seconds on a Dell Precision T5400.

Cf. Arndt • Haenel, \(\pi\) - Unleashed
6.4 Spigot algorithm for e
p.85

A similar program (roemer) was a winning entry at the 6th International Obfuscated C Code Contest (1989):
Code:

                                                                        char
                                                            _3141592654[3141
          ],__3141[3141];_314159[31415],_3141[31415];main(){register char*
      _3_141,*_3_1415, *_3__1415; register int _314,_31415,__31415,*_31,
    _3_14159,__3_1415;*_3141592654=__31415=2,_3141592654[0][_3141592654
   -1]=1[__3141]=5;__3_1415=1;do{_3_14159=_314=0,__31415++;for( _31415
  =0;_31415<(3,14-4)*__31415;_31415++)_31415[_3141]=_314159[_31415]= -
1;_3141[*_314159=_3_14159]=_314;_3_141=_3141592654+__3_1415;_3_1415=
__3_1415    +__3141;for                 (_31415 = 3141-
           __3_1415  ;                  _31415;_31415--
           ,_3_141 ++,                  _3_1415++){_314
           +=_314<<2 ;                  _314<<=1;_314+=
          *_3_1415;_31                   =_314159+_314;
          if(!(*_31+1)                   )* _31 =_314 /
          __31415,_314                   [_3141]=_314 %
          __31415 ;* (                   _3__1415=_3_141
         )+= *_3_1415                     = *_31;while(*
         _3__1415 >=                      31415/3141 ) *
         _3__1415+= -                     10,(*--_3__1415
        )++;_314=_314                     [_3141]; if ( !
        _3_14159 && *                     _3_1415)_3_14159
        =1,__3_1415 =                     3141-_31415;}if(
        _314+(__31415                      >>1)>=__31415 )
        while ( ++ *                       _3_141==3141/314
       )*_3_141--=0                        ;}while(_3_14159
       ) ; { char *                        __3_14= "3.1415";
       write((3,1),                        (--*__3_14,__3_14
       ),(_3_14159                          ++,++_3_14159))+
      3.1415926; }                          for ( _31415 = 1;
     _31415<3141-                           1;_31415++)write(
    31415% 314-(                            3,14),_3141592654[
  _31415    ] +                            "0123456789","314"
  [ 3]+1)-_314;                            puts((*_3141592654=0
,_3141592654))                              ;_314= *"3.141592";}

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(16C) e to 400 decimal places - Rick314 - 02-06-2015, 02:12 AM
RE: (HP-16C) e to 400 decimal places - Thomas Klemm - 02-12-2015 06:53 PM



User(s) browsing this thread: 1 Guest(s)